| libpreludedb Reference Manual | ||||
|---|---|---|---|---|
| Top | Description | ||||
#define PRELUDEDB_SQL_TIMESTAMP_STRING_SIZE enum preludedb_sql_time_constraint_type_t; typedef preludedb_sql_t; typedef preludedb_sql_table_t; typedef preludedb_sql_row_t; typedef preludedb_sql_field_t; int preludedb_sql_new (preludedb_sql_t **newdb,const char *type,preludedb_sql_settings_t *settings); void preludedb_sql_destroy (preludedb_sql_t *sql); int preludedb_sql_enable_query_logging (preludedb_sql_t *sql,const char *filename); void preludedb_sql_disable_query_logging (preludedb_sql_t *sql); const char * preludedb_sql_get_plugin_error (preludedb_sql_t *sql); int preludedb_sql_query (preludedb_sql_t *sql,const char *query,preludedb_sql_table_t **table); int preludedb_sql_query_sprintf (preludedb_sql_t *sql,preludedb_sql_table_t **table,const char *format,...); int preludedb_sql_insert (preludedb_sql_t *sql,const char *table,const char *fields,const char *format,...); int preludedb_sql_build_limit_offset_string (preludedb_sql_t *sql,int limit,int offset,prelude_string_t *output); int preludedb_sql_transaction_start (preludedb_sql_t *sql); int preludedb_sql_transaction_end (preludedb_sql_t *sql); int preludedb_sql_transaction_abort (preludedb_sql_t *sql); int preludedb_sql_escape_fast (preludedb_sql_t *sql,const char *input,size_t input_size,char **output); int preludedb_sql_escape (preludedb_sql_t *sql,const char *input,char **output); int preludedb_sql_escape_binary (preludedb_sql_t *sql,const unsigned char *input,size_t input_size,char **output); int preludedb_sql_unescape_binary (preludedb_sql_t *sql,const char *input,size_t input_size,unsigned char **output,size_t *output_size); void preludedb_sql_table_destroy (preludedb_sql_table_t *table); const char * preludedb_sql_table_get_column_name (preludedb_sql_table_t *table,unsigned int column_num); int preludedb_sql_table_get_column_num (preludedb_sql_table_t *table,const char *column_name); unsigned int preludedb_sql_table_get_column_count (preludedb_sql_table_t *table); unsigned int preludedb_sql_table_get_row_count (preludedb_sql_table_t *table); int preludedb_sql_table_fetch_row (preludedb_sql_table_t *table,preludedb_sql_row_t **row); int preludedb_sql_row_fetch_field (preludedb_sql_row_t *row,int column_num,preludedb_sql_field_t **field); int preludedb_sql_row_fetch_field_by_name (preludedb_sql_row_t *row,const char *column_name,preludedb_sql_field_t **field); char * preludedb_sql_field_get_value (preludedb_sql_field_t *field); size_t preludedb_sql_field_get_len (preludedb_sql_field_t *field); int preludedb_sql_field_to_int8 (preludedb_sql_field_t *field,int8_t *value); int preludedb_sql_field_to_uint8 (preludedb_sql_field_t *field,uint8_t *value); int preludedb_sql_field_to_int16 (preludedb_sql_field_t *field,int16_t *value); int preludedb_sql_field_to_uint16 (preludedb_sql_field_t *field,uint16_t *value); int preludedb_sql_field_to_int32 (preludedb_sql_field_t *field,int32_t *value); int preludedb_sql_field_to_uint32 (preludedb_sql_field_t *field,uint32_t *value); int preludedb_sql_field_to_int64 (preludedb_sql_field_t *field,int64_t *value); int preludedb_sql_field_to_uint64 (preludedb_sql_field_t *field,uint64_t *value); int preludedb_sql_field_to_float (preludedb_sql_field_t *field,float *value); int preludedb_sql_field_to_double (preludedb_sql_field_t *field,double *value); int preludedb_sql_field_to_string (preludedb_sql_field_t *field,prelude_string_t *output); int preludedb_sql_build_criterion_string (preludedb_sql_t *sql,prelude_string_t *output,const char *field,idmef_criterion_operator_t idmef_operator,idmef_criterion_value_t *value); int preludedb_sql_time_from_timestamp (idmef_time_t *time,const char *time_buf,int32_t gmtoff,uint32_t usec); int preludedb_sql_time_to_timestamp (preludedb_sql_t *sql,const idmef_time_t *time,char *time_buf,size_t time_buf_size,char *gmtoff_buf,size_t gmtoff_buf_size,char *usec_buf,size_t usec_buf_size);
typedef enum {
PRELUDEDB_SQL_TIME_CONSTRAINT_YEAR = 8,
PRELUDEDB_SQL_TIME_CONSTRAINT_MONTH = 1,
PRELUDEDB_SQL_TIME_CONSTRAINT_YDAY = 2,
PRELUDEDB_SQL_TIME_CONSTRAINT_MDAY = 3,
PRELUDEDB_SQL_TIME_CONSTRAINT_WDAY = 4,
PRELUDEDB_SQL_TIME_CONSTRAINT_HOUR = 5,
PRELUDEDB_SQL_TIME_CONSTRAINT_MIN = 6,
PRELUDEDB_SQL_TIME_CONSTRAINT_SEC = 7,
PRELUDEDB_SQL_TIME_CONSTRAINT_MSEC = 9,
PRELUDEDB_SQL_TIME_CONSTRAINT_USEC = 10,
PRELUDEDB_SQL_TIME_CONSTRAINT_QUARTER = 11
} preludedb_sql_time_constraint_type_t;
int preludedb_sql_new (preludedb_sql_t **newdb,const char *type,preludedb_sql_settings_t *settings);
This function initialize the new object, load and setup the plugin that
handle the database named type with the configuration stored in settings.
|
Type of the database. |
|
Settings for the choosen database. |
Returns : |
0 on success or a negative value if an error occur. |
void preludedb_sql_destroy (preludedb_sql_t *sql);
Destroy sql and the underlying plugin.
|
Pointer to a sql object. |
int preludedb_sql_enable_query_logging (preludedb_sql_t *sql,const char *filename);
Log all queries in the specified file.
|
Pointer to a sql object. |
|
Where the logs will be written. |
Returns : |
0 on success, or a negative value if an error occur. |
void preludedb_sql_disable_query_logging (preludedb_sql_t *sql);
Disable query logging.
|
Pointer to a sql object. |
const char * preludedb_sql_get_plugin_error (preludedb_sql_t *sql);
preludedb_sql_get_plugin_error is deprecated and should not be used in newly-written code. Use preludedb_strerror().
Get sql plugin specific error message.
|
Pointer to a sql object. |
Returns : |
a non NULL pointer or a NULL pointer if no error is available. |
int preludedb_sql_query (preludedb_sql_t *sql,const char *query,preludedb_sql_table_t **table);
Execute a SQL query.
|
Pointer to a sql object. |
|
The SQL query to execute. |
|
Pointer to a table where the query result will be stored if the type of query return results (i.e a SELECT can results, but an INSERT never results) and if the query is sucessfull. |
Returns : |
1 if result are available, 0 for no result, -1 if an error occured. |
int preludedb_sql_query_sprintf (preludedb_sql_t *sql,preludedb_sql_table_t **table,const char *format,...);
Execute a SQL query.
|
Pointer to a sql object. |
|
Pointer to a table where the query result will be stored if the type of query return results (i.e a SELECT can results, but an INSERT never results) and if the query is sucessfull. |
|
The SQL query to execute in a printf format string. |
|
Arguments referenced in format. |
Returns : |
1 if the query returns results, 0 if it does not, or negative value if an error occur. |
int preludedb_sql_insert (preludedb_sql_t *sql,const char *table,const char *fields,const char *format,...);
Insert values in a table.
|
Pointer to a sql object. |
|
the name of the table where to insert values. |
|
a list of comma separated field names where the values will be inserted. |
|
The values to insert in a printf format string. |
|
Argument referenced throught format. |
Returns : |
0 on success or a negative value if an error occur. |
int preludedb_sql_build_limit_offset_string (preludedb_sql_t *sql,int limit,int offset,prelude_string_t *output);
Build a limit/offset string for a SQL query, depending on the underlying type of database.
|
Pointer to a sql object. |
|
The limit value, a value inferior to zero will disable the limit. |
|
The offset value, a value inferior to zero will disable the offset. |
|
Where the limit/offset built string will be stored. |
Returns : |
0 on success or a negative value if an error occur. |
int preludedb_sql_transaction_start (preludedb_sql_t *sql);
Begin a sql transaction.
|
Pointer to a sql object. |
Returns : |
0 on success or a negative value if an error occur. |
int preludedb_sql_transaction_end (preludedb_sql_t *sql);
Finish a sql transaction (SQL COMMIT command).
|
Pointer to a sql object. |
Returns : |
0 on success or a negative value if an error occur. |
int preludedb_sql_transaction_abort (preludedb_sql_t *sql);
Abort a sql transaction (SQL ROLLBACK command).
|
Pointer to a sql object. |
Returns : |
0 on success or a negative value if an error occur. |
int preludedb_sql_escape_fast (preludedb_sql_t *sql,const char *input,size_t input_size,char **output);
Escape a string buffer.
|
Pointer to a sql object. |
|
Buffer to escape |
|
Buffer size. |
|
Where the new escaped buffer will be stored. |
Returns : |
0 on success or a negative value if an error occur. |
int preludedb_sql_escape (preludedb_sql_t *sql,const char *input,char **output);
Escape a string buffer.
|
Pointer to a sql object. |
|
Buffer to escape. |
|
Where the new escaped buffer will be stored. |
Returns : |
0 on success or a negative value if an error occur. |
int preludedb_sql_escape_binary (preludedb_sql_t *sql,const unsigned char *input,size_t input_size,char **output);
Escape a binary buffer.
|
Pointer to a sql object. |
|
Buffer to escape. |
|
Buffer size. |
|
Where the new escaped buffer will be stored. |
Returns : |
0 on success or a negative value if an error occur. |
int preludedb_sql_unescape_binary (preludedb_sql_t *sql,const char *input,size_t input_size,unsigned char **output,size_t *output_size);
Unescape to a binary buffer.
|
Pointer to a sql object. |
|
Buffer to unescape. |
|
Buffer size. |
|
Where the new unescaped buffer will be stored. |
|
Size of the new unescape buffer. |
Returns : |
0 on success or a negative value if an error occur. |
void preludedb_sql_table_destroy (preludedb_sql_table_t *table);
Destroy the table object.
|
Pointer to a table object. |
const char * preludedb_sql_table_get_column_name (preludedb_sql_table_t *table,unsigned int column_num);
Get the name of the column number column_num.
|
Pointer to a table object. |
|
Column number. |
Returns : |
the name of the column or NULL if the column column_num could not be found. |
int preludedb_sql_table_get_column_num (preludedb_sql_table_t *table,const char *column_name);
Get the number of the column named column_name.
|
Pointer to a table object. |
|
Column name. |
Returns : |
the number of the column or -1 if the column column_name could not be found. |
unsigned int preludedb_sql_table_get_column_count
(preludedb_sql_table_t *table);
Get the the number of columns.
|
Pointer to a table object. |
Returns : |
the number of columns. |
unsigned int preludedb_sql_table_get_row_count (preludedb_sql_table_t *table);
Get the the number of row in the table. Depending on the database backend, this might require retrieving all rows.
|
Pointer to a table object. |
Returns : |
the number of columns. |
int preludedb_sql_table_fetch_row (preludedb_sql_table_t *table,preludedb_sql_row_t **row);
Fetch the next table's row.
|
Pointer to a table object. |
|
Pointer to the row object where the result will be stored. |
Returns : |
1 if the table returns a new row, 0 if there is no more rows to fetch or a negative value if an error occur. |
int preludedb_sql_row_fetch_field (preludedb_sql_row_t *row,int column_num,preludedb_sql_field_t **field);
preludedb_sql_row_fetch_field is deprecated and should not be used in newly-written code. use preludedb_sql_row_get_field() instead.
Fetch the field of column column_num
|
Pointer to a row object. |
|
The column number of the field to be fetched. |
|
Pointer to the field object where the result will be stored. |
Returns : |
1 if the row returns a non-empty field, 0 if it returns an empty field, or a negative value if an error occur. |
int preludedb_sql_row_fetch_field_by_name (preludedb_sql_row_t *row,const char *column_name,preludedb_sql_field_t **field);
preludedb_sql_row_fetch_field_by_name is deprecated and should not be used in newly-written code. use preludedb_sql_row_get_field_by_name() instead.
Fetch the field of column column_name
|
Pointer to a row object. |
|
The column name of the field to be fetched. |
|
Pointer to the field object where the result will be stored. |
Returns : |
1 if the row returns a non-empty field, 0 if it returns an empty field, or a negative value if an error occur. |
char * preludedb_sql_field_get_value (preludedb_sql_field_t *field);
Get the raw value of the field.
|
Pointer to a field object. |
Returns : |
field value. |
size_t preludedb_sql_field_get_len (preludedb_sql_field_t *field);
Get the field value length.
|
Pointer to a field object. |
Returns : |
field value length. |
int preludedb_sql_field_to_int8 (preludedb_sql_field_t *field,int8_t *value);
int preludedb_sql_field_to_uint8 (preludedb_sql_field_t *field,uint8_t *value);
int preludedb_sql_field_to_int16 (preludedb_sql_field_t *field,int16_t *value);
int preludedb_sql_field_to_uint16 (preludedb_sql_field_t *field,uint16_t *value);
int preludedb_sql_field_to_int32 (preludedb_sql_field_t *field,int32_t *value);
int preludedb_sql_field_to_uint32 (preludedb_sql_field_t *field,uint32_t *value);
int preludedb_sql_field_to_int64 (preludedb_sql_field_t *field,int64_t *value);
int preludedb_sql_field_to_uint64 (preludedb_sql_field_t *field,uint64_t *value);
int preludedb_sql_field_to_float (preludedb_sql_field_t *field,float *value);
int preludedb_sql_field_to_double (preludedb_sql_field_t *field,double *value);
int preludedb_sql_field_to_string (preludedb_sql_field_t *field,prelude_string_t *output);
Get the string value of field.
|
Pointer to a field type. |
|
Pointer to a string object where the field value will be added. |
Returns : |
0 on success, or a negative value if an error occur. |
int preludedb_sql_build_criterion_string (preludedb_sql_t *sql,prelude_string_t *output,const char *field,idmef_criterion_operator_t idmef_operator,idmef_criterion_value_t *value);
Build a sql "field operator value" string.
|
Pointer to a sql object. |
|
Pointer to a string object, where the result content will be stored. |
|
The sql field name. |
|
The criterion value. |
Returns : |
0 on success, or a negative value if an error occur. |
int preludedb_sql_time_from_timestamp (idmef_time_t *time,const char *time_buf,int32_t gmtoff,uint32_t usec);
Set an idmef time using the timestamp, GMT offset and microseconds given in input.
|
Pointer to a time object. |
|
SQL timestamp. |
|
GMT offset. |
|
Microseconds. |
Returns : |
0 on success, or a negative value if an error occur. |
int preludedb_sql_time_to_timestamp (preludedb_sql_t *sql,const idmef_time_t *time,char *time_buf,size_t time_buf_size,char *gmtoff_buf,size_t gmtoff_buf_size,char *usec_buf,size_t usec_buf_size);
Set timestamp, GMT offset, and microseconds buffers with the idmef time object given in input.
|
Pointer to a time object. |
|
SQL timestamp. |
|
SQL timestamp buffer size. |
|
GMT offset buffer. |
|
GMT offset buffer size. |
|
Microseconds buffer. |
|
Microseconds buffer size. |
Returns : |
0 on success, or a negative value if an error occur. |