33 col_text = calloc(NumTextBytes + 1,
sizeof(
char));
36 ERROR_RETURN(
"Allocating test text data failed.")
39 for (i = 0; i < NumTextBytes; i++) col_text[i] =
'a';
44 int main(
int argc,
char** argv)
49 char* TestTable =
"TestsqlCopy";
50 char col_vc[40] =
"This is \n\r column vc[40] 123456789\r";
60 clock_t StartTime, EndTime;
66 printf(
"Usage: %s RowsToTest NumTextBytes CopyDataBufferSize\n", argv[0]);
74 RowsToTest = atoi(argv[1]);
75 NumTextBytes = atoi(argv[2]);
76 CopyBufSize = atoi(argv[3]);
80 datasize = NumTextBytes + 8 + 40 + 1;
81 DataBuf = calloc(datasize,
sizeof(
char));
85 ERROR_RETURN(
"Allocating test data buffer failed.")
92 snprintf(sql,
sizeof(sql),
"create table %s (col_int integer, col_text text, col_vc varchar(40))", TestTable);
93 result = PQexec(pgConn, sql);
101 "col_int",
"col_text",
"col_vc");
105 for (RowNum = 0; RowNum < RowsToTest; RowNum++)
107 snprintf(DataBuf, datasize,
"%d\t%s\t%s\n", RowNum, col_text, col_vc);
117 printf(
"%.6f Seconds to load.\n", ((
double) (EndTime - StartTime)) / CLOCKS_PER_SEC);
120 snprintf(sql,
sizeof(sql),
"select count(*) from %s", TestTable);
121 result = PQexec(pgConn, sql);
123 printf(
"%d records inserted, %d expected\n",
124 atoi(PQgetvalue(result, 0, 0)),
char * DBConfFile
DB conf file location.
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
char * GetTextCol(int NumTextBytes)
PGconn * pgConn
Database connection.
int fo_checkPQcommand(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres commands (not select) If an error occured, write the error to s...
The main FOSSology C library.
psqlCopy_t fo_sqlCopyCreate(PGconn *pGconn, char *TableName, int BufSize, int NumColumns,...)
Constructor for sqlCopy_struct.
void fo_sqlCopyDestroy(psqlCopy_t pCopy, int ExecuteFlag)
Destructor for sqlCopy_struct.
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.
int fo_sqlCopyAdd(psqlCopy_t pCopy, char *DataRow)
Add a data row to an sqlCopy Use '' to pass in a null.