DBTCP FUNCTIONS
MY_BSTRING - Struct to handle binary strings that can grow dynamicly
MY_STRING - Struct to handle strings that can grow dynamicly
MY_ARRAY - Struct to handle
typedef struct _dbftp_result {
/* Network communication */
int sock; /* Socket used to connect to the server */
MY_BSTRING *net_buf; /* Buffer for network comunication */
/* Results from the remote server */
struct MY_STRING dsn; /* DSN connect string */
struct MY_STRING error; /* Error string from the remote server */
int errorno;
struct MY_ARRAY *field; /* Result set field structure */
struct MY_ARRAY *cols; /* Result set actual row */
int num_fields;
} dbftp_result;
dbftp_result *init_dbftp_result ( void )
Create an empty dbftp_result structure and returns a pointer to it.
Return values:
NULL - Error allocating the new structure
!= NULL - Pointer to the new structure
int free_dbftp_result ( dbftp_result *myresults )
Release a previously allocated dbftp_result structure.
int dbftp_connect ( dbftp_result *myres, char *host, int port, char *dsn )
Connect to dbtcp server at 'host' on port 'port' and tries to use the 'dsn' DSN.
Return values:
OK - Successfully connected
ERR - Error, use dbftp_error_string to view the error message
int dbftp_sql ( dbftp_result *myres, char *query )
Send a query string 'query' to the remote server.
Return values:
OK - Query sent and succesfully executed
ERR - Error, use dbftp_error_string to view the error message
dbftp_fetch_row ( dbftp_result *myres )
Fetch the next row of the result set.
Return values:
FETCH_OK - Fetched a row
FETCH_ERROR - Unable to get the next row
FETCH_EOF - No more rows
int dbftp_close ( dbftp_result *myres )
Close the connection 'myres'.
Return values:
OK - Connection closed
ERR - Error closing connection
int dbftp_fetch_fields ( dbftp_result *myres )
Fetch the structure of the result set.
Return values:
OK - Structure fetched
ERR - Error, use dbftp_error_string to view the error message
char *dbftp_field_name ( dbftp_result *myres, int n )
Returns a pointer to a string ( allocated in the dbftp_result structure ) that contains the name of the n-th field.
If n is not a valid field number returns NULL.
Return values:
NULL - No such field in the record set
!= NULL - Pointer to the name of the field
int dbftp_field_len ( dbftp_result *myres, int n )
Returns the length in bytes of the n-th field.
Not the length of the value but the length of the field
If n is not a valid field returns -1.
Return values:
>0 - Length of the n-th field
-1 - No such field in the record set
int dbftp_field_type ( dbftp_result *myres, int field )
Returns the type of the n-th field.
If n is not a valid field returns -1.
Return values:
'N' - 116 - Number
'D' - 104 - Date in format 'YYYY-MM-DD'
'd' - 144 - Date in format 'YYYY-MM-DD HH:MM:SS'
'C' - 103 - Character string
char *dbftp_fetch_value ( dbftp_result *myres, int col )
Returns a pointer to a string ( allocated in the dbftp_result structure ) that contains the value of the n-th field.
if n is not a valid field returns NULL.
Return values:
NULL - No such field in the record set
!= NULL - Pointer to the value of the field
int dbftp_num_field( dbftp_result *myres )
Returns the number of fields of the result recordset.
char *dbftp_error_string( dbftp_result *myres )
Returns a pointer to the error string returned by the last function.
The buffer is allocated in the dbftp_result structure.