FOSSology
4.4.0
Open Source License Compliance by Open Source Software
|
sqlCopy buffers sql inserts and performs batch copy's to the database. Why do this? Because this method is roughtly 15x faster than individual sql inserts for a typical fossology table insert. More...
#include "sqlCopy.h"
Go to the source code of this file.
Macros | |
#define | growby 128 |
Grow DataBuf by this number of bytes. | |
Functions | |
psqlCopy_t | fo_sqlCopyCreate (PGconn *pGconn, char *TableName, int BufSize, int NumColumns,...) |
Constructor for sqlCopy_struct. More... | |
int | fo_sqlCopyAdd (psqlCopy_t pCopy, char *DataRow) |
Add a data row to an sqlCopy Use '\N' to pass in a null. More... | |
int | fo_sqlCopyExecute (psqlCopy_t pCopy) |
Execute the copy (ie insert the buffered records into the database). More... | |
void | fo_sqlCopyDestroy (psqlCopy_t pCopy, int ExecuteFlag) |
Destructor for sqlCopy_struct. More... | |
void | fo_sqlCopyPrint (psqlCopy_t pCopy, int PrintBytes) |
Print the sqlCopy_struct. More... | |
sqlCopy buffers sql inserts and performs batch copy's to the database. Why do this? Because this method is roughtly 15x faster than individual sql inserts for a typical fossology table insert.
Note that data to be inserted is stored in memory (pCopy->DataBuf), not an external file. So the caller should give some consideration to the number of records buffered.
Definition in file sqlCopy.c.
int fo_sqlCopyAdd | ( | psqlCopy_t | pCopy, |
char * | DataRow | ||
) |
Add a data row to an sqlCopy Use '\N' to pass in a null.
pCopy | Pointer to sqlCopy struct |
DataRow | Row to insert |
The fields in DataRow needs to be tab delimited. All strings should be escaped with PQescapeStringConn() For example, to insert a row with two character fields and an integer field, DataRow might look like: Mydata<tab>string <tab> string number 2 <tab> 36 This could be created by: snprintf(buf, sizeof(buf), "%s\t%s\t%d\n", str1, str2, val);
psqlCopy_t fo_sqlCopyCreate | ( | PGconn * | pGconn, |
char * | TableName, | ||
int | BufSize, | ||
int | NumColumns, | ||
... | |||
) |
Constructor for sqlCopy_struct.
pGconn | Database connection |
TableName | Table to be used |
BufSize | Size of the copy buffer in bytes. If BufSize is smaller than needed to hold any single row, then BufSize is automatically increased. |
NumColumns | number of column names passed in. |
... | Variable char *ColumnNames |
void fo_sqlCopyDestroy | ( | psqlCopy_t | pCopy, |
int | ExecuteFlag | ||
) |
Destructor for sqlCopy_struct.
This will execute fo_sqlCopyExecute() if the ExecuteFlag is true and there are records that need to be written.
pCopy | Pointer to sqlCopy struct |
ExecuteFlag | 0 if DataRows should not be written, 1 if DataRows should be written |
int fo_sqlCopyExecute | ( | psqlCopy_t | pCopy | ) |
void fo_sqlCopyPrint | ( | psqlCopy_t | pCopy, |
int | PrintBytes | ||
) |
Print the sqlCopy_struct.
This is used for debugging.
pCopy | Pointer to sqlCopy struct |
PrintBytes | Number of DataBuf bytes to print. If zero, print the whole buffer. |