25 #include <csutil/scf.h>    26 #include <csutil/scf_implementation.h>    27 #include <csutil/threading/thread.h>    29 #include "iutil/comp.h"    35 #include <csutil/csstring.h>    41 struct iObjectRegistry;
    45     #ifdef USE_DELAY_QUERY    46     #define THREADED_BUFFER_SIZE 300    47     class DelayedQueryManager : 
public CS::Threading::Runnable
    50         DelayedQueryManager(
const char *host, 
unsigned int port, 
const char *database,
    51                                   const char *user, 
const char *pwd);
    54         void Push(csString query);
    57         csString arr[THREADED_BUFFER_SIZE];
    59         CS::Threading::Mutex mutex;
    60         CS::Threading::RecursiveMutex mutexArray;
    61         CS::Threading::Condition datacondition;
    72     class psMysqlConnection : 
public scfImplementation2<psMysqlConnection, iComponent, iDataConnection>
    79         iObjectRegistry *objectReg;
    85         psMysqlConnection(
iBase *iParent);
    86         virtual ~psMysqlConnection();
    89         bool Initialize(
const char *host, 
unsigned int port, 
const char *database, 
    90                         const char *user, 
const char *pwd, 
LogCSV* logcsv);
    99         void Escape(csString& to, 
const char *from);
   101         iResultSet *Select(
const char *sql,...);
   102         int SelectSingleNumber(
const char *sql, ...);
   103         unsigned long Command(
const char *sql,...);
   104         unsigned long CommandPump(
const char *sql,...);
   106         uint64 GenericInsertWithID(
const char *table,
const char **fieldnames,
psStringArray& fieldvalues);
   107         bool GenericUpdateWithID(
const char *table,
const char *idfield,
const char *
id,
const char **fieldnames,
psStringArray& fieldvalues);
   108         bool GenericUpdateWithID(
const char *table,
const char *idfield,
const char *
id,
psStringArray& fields);
   110         const char *GetLastError(
void);
   111         const char *GetLastQuery(
void)
   115         uint64 GetLastInsertID();
   117         const char *uint64tostring(uint64 value,csString& recv);
   119         virtual const char* DumpProfile();
   120         virtual void ResetProfile();
   122         iRecord* NewUpdatePreparedStatement(
const char* table, 
const char* idfield, 
unsigned int count, 
const char* file, 
unsigned int line);
   123         iRecord* NewInsertPreparedStatement(
const char* table, 
unsigned int count, 
const char* file, 
unsigned int line);
   125     #ifdef USE_DELAY_QUERY       126         csRef<DelayedQueryManager> dqm;
   127         csRef<Thread> dqmThread;
   132     class psResultRow : 
public iResultRow
   146         void SetMaxFields(
int fields)  {    max = fields;   };
   147         void SetResultSet(
void* resultsettoken);
   151         const char *operator[](
int whichfield);
   152         const char *operator[](
const char *fieldname);
   154         const char* GetString(
int whichfield);
   155         const char* GetString(
const char *fieldname);
   157         int GetInt(
int whichfield);
   158         int GetInt(
const char *fieldname);
   160         unsigned long GetUInt32(
int whichfield);
   161         unsigned long GetUInt32(
const char *fieldname);
   163         float GetFloat(
int whichfield);
   164         float GetFloat(
const char *fieldname);
   166         uint64 GetUInt64(
int whichfield);
   167         uint64 GetUInt64(
const char *fieldname);
   169         uint64 stringtouint64(
const char *stringbuf);
   170         const char *uint64tostring(uint64 value,
char *stringbuf,
int buflen);
   173     class psResultSet : 
public iResultSet
   177         unsigned long rows, fields, current;
   181         psResultSet(PGresult *res);
   182         virtual ~psResultSet();
   184         void Release(
void) { 
delete this; };
   186         iResultRow& operator[](
unsigned long whichrow);
   188         unsigned long Count(
void) { 
return rows; };
   191     class dbRecord : 
public iRecord
   194         enum FIELDTYPE { SQL_TYPE_FLOAT, SQL_TYPE_INT, SQL_TYPE_STRING, SQL_TYPE_NULL };
   224         virtual void AddToStatement(
const char* fname) = 0;
   226         virtual void SetID(uint32 uid) = 0;
   229         dbRecord(PGconn* 
db, 
int *StmtNum, 
const char* Table, 
const char* Idfield, 
unsigned int count, 
LogCSV* logcsv, 
const char* file, 
unsigned int line)
   234             temp = 
new StatField[count];
   237             this->logcsv = logcsv;
   255         void AddField(
const char* fname, 
float fValue);
   257         void AddField(
const char* fname, 
int iValue);
   259         void AddField(
const char* fname, 
unsigned int uiValue);
   261         void AddField(
const char* fname, 
unsigned short usValue);
   263         void AddField(
const char* fname, 
const char* sValue);
   265         void AddFieldNull(
const char* fname);
   267         virtual bool Prepare() = 0;
   269         virtual bool Execute(uint32 uid);
   272     class dbInsert : 
public dbRecord
   274         virtual void AddToStatement(
const char* fname)
   280         virtual void SetID(uint32 ) {};
   283         dbInsert(PGconn* 
db, 
int *StmtNum, 
const char* Table, 
unsigned int count, 
LogCSV* logcsv, 
const char* file, 
unsigned int line)
   284         : dbRecord(db, StmtNum, Table, 
"", count, logcsv, file, line) { }
   286         virtual bool Prepare();
   289     class dbUpdate : 
public dbRecord
   291         virtual void AddToStatement(
const char* fname)
   294                 command.FormatPush(
"%s = $", fname);
   297         virtual void SetID(uint32 uid) 
   299             temp[index].iValue = uid;
   300             temp[index].type = SQL_TYPE_INT;
   304         dbUpdate(PGconn* 
db, 
int *StmtNum, 
const char* Table, 
const char* Idfield, 
unsigned int count, 
LogCSV* logcsv, 
const char* file, 
unsigned int line)
   305         : dbRecord(db, StmtNum, Table, Idfield, count, logcsv, file, line) { }
   306         virtual bool Prepare();
   310 CS_PLUGIN_NAMESPACE_END(dbpostgresql)
 
iDataConnection * db
Global connection to the Database. Set from the psDatabase class. 
 
CS_PLUGIN_NAMESPACE_BEGIN(dbmysql)
 
Statistics of time consumed by SQL statements. 
 
void void Initialize(iObjectRegistry *object_reg)
 
A slightly improved version of csStringArray, sporting the handy FormatPush method.