pgdatabase.cc
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:3k
源码类别:

数据库系统

开发平台:

Unix_Linux

  1. /*-------------------------------------------------------------------------
  2.  *
  3.  *   FILE
  4.  *      pgdatabase.cpp
  5.  *
  6.  *   DESCRIPTION
  7.  *      implementation of the PgDatabase class.
  8.  *   PgDatabase encapsulates some utility routines
  9.  *
  10.  * Copyright (c) 1994, Regents of the University of California
  11.  *
  12.  * IDENTIFICATION
  13.  *   $Header: /usr/local/cvsroot/pgsql/src/interfaces/libpq++/pgdatabase.cc,v 1.3 1999/06/05 18:05:17 tgl Exp $
  14.  *
  15.  *-------------------------------------------------------------------------
  16.  */
  17.  
  18. #include "pgdatabase.h"
  19. void PgDatabase::DisplayTuples(FILE *out, int fillAlign, 
  20.    const char* fieldSep, int printHeader,
  21.    int /* quiet */) 
  22. {
  23. PQprintOpt po;
  24. memset(&po,0,sizeof(po));
  25. po.align = (pqbool)fillAlign;
  26. po.fieldSep = (char *)fieldSep;
  27. po.header = (pqbool)printHeader;
  28. PQprint(out,pgResult,&po);
  29. }
  30. void PgDatabase::PrintTuples(FILE *out, int printAttName, int terseOutput,
  31.  int width)
  32. {
  33. PQprintOpt po;
  34. memset(&po,0,sizeof(po));
  35. po.align = (pqbool)width;
  36. if(terseOutput) po.fieldSep = strdup("|");
  37. else po.fieldSep = "";
  38. po.header = (pqbool)printAttName;
  39. PQprint(out,pgResult,&po);
  40. }
  41. int PgDatabase::Tuples()
  42. return PQntuples(pgResult); 
  43. }
  44. int PgDatabase::Fields()
  45. return PQnfields(pgResult); 
  46. }
  47. const char* PgDatabase::FieldName(int field_num)
  48. return PQfname(pgResult, field_num); 
  49. }
  50. int PgDatabase::FieldNum(const char* field_name)
  51. return PQfnumber(pgResult, field_name); 
  52. }
  53. Oid PgDatabase::FieldType(int field_num)
  54. return PQftype(pgResult, field_num); 
  55. }
  56. Oid PgDatabase::FieldType(const char* field_name)
  57. return PQftype(pgResult, FieldNum(field_name)); 
  58. }
  59. short PgDatabase::FieldSize(int field_num)
  60. return PQfsize(pgResult, field_num); 
  61. }
  62. short PgDatabase::FieldSize(const char* field_name)
  63. return PQfsize(pgResult, FieldNum(field_name)); 
  64. }
  65. const char* PgDatabase::GetValue(int tup_num, int field_num)
  66. return PQgetvalue(pgResult, tup_num, field_num); 
  67. }
  68. const char* PgDatabase::GetValue(int tup_num, const char* field_name)
  69. return PQgetvalue(pgResult, tup_num, FieldNum(field_name)); 
  70. }
  71. int PgDatabase::GetLength(int tup_num, int field_num)
  72. return PQgetlength(pgResult, tup_num, field_num); 
  73. }
  74. int PgDatabase::GetLength(int tup_num, const char* field_name)
  75. return PQgetlength(pgResult, tup_num, FieldNum(field_name)); 
  76. }
  77. int PgDatabase::GetLine(char* string, int length)
  78. return PQgetline(pgConn, string, length); 
  79. }
  80. void PgDatabase::PutLine(const char* string)
  81. PQputline(pgConn, string); 
  82. }
  83. const char* PgDatabase::OidStatus()
  84. return PQoidStatus(pgResult); 
  85. }
  86. int PgDatabase::EndCopy()
  87. return PQendcopy(pgConn); 
  88. }