mysql_query.c File Reference

#include <sys/types.h>
#include <string.h>
#include <stdio.h>
#include <mvp_refmem.h>
#include <cmyth.h>
#include <cmyth_local.h>

Go to the source code of this file.

Data Structures

struct  cmyth_mysql_query_s
 Hold in-progress query. More...

Defines

#define CMYTH_ULONG_STRLEN   ((sizeof(long)*3)+1)
#define CMYTH_LONG_STRLEN   (CMYTH_ULONG_STRLEN+1)

Functions

static void query_destroy (void *p)
 Internal only! Registered as callback to de-allocate actual buffer if the query is de-allocated.
cmyth_mysql_query_tcmyth_mysql_query_create (cmyth_database_t db, const char *query_string)
 Allocate a dynamic query string to have parameters added to it.
void cmyth_mysql_query_reset (cmyth_mysql_query_t *query)
static int query_buffer_check_len (cmyth_mysql_query_t *query, int len)
static int query_buffer_add (cmyth_mysql_query_t *query, const char *buf, int len)
static int query_buffer_add_str (cmyth_mysql_query_t *query, const char *str)
static int query_buffer_add_escape_str (cmyth_mysql_query_t *query, const char *str)
static int query_begin_next_param (cmyth_mysql_query_t *query)
static int query_buffer_add_long (cmyth_mysql_query_t *query, long param)
static int query_buffer_add_ulong (cmyth_mysql_query_t *query, long param)
int cmyth_mysql_query_param_long (cmyth_mysql_query_t *query, long param)
 Add a long integer parameter.
int cmyth_mysql_query_param_ulong (cmyth_mysql_query_t *query, unsigned long param)
 Add an unsigned long integer parameter.
int cmyth_mysql_query_param_int (cmyth_mysql_query_t *query, int param)
 Add an integer parameter.
int cmyth_mysql_query_param_uint (cmyth_mysql_query_t *query, int param)
 Add an unsigned integer parameter.
int cmyth_mysql_query_param_unixtime (cmyth_mysql_query_t *query, time_t param)
 Add, and convert a unixtime to mysql date/timestamp.
int cmyth_mysql_query_param_str (cmyth_mysql_query_t *query, const char *param)
 Add (including adding quotes), and escape a string parameter.
char * cmyth_mysql_query_string (cmyth_mysql_query_t *query)
 Get the completed query string.
MYSQL_RES * cmyth_mysql_query_result (cmyth_mysql_query_t *query)


Define Documentation

#define CMYTH_LONG_STRLEN   (CMYTH_ULONG_STRLEN+1)
 

Definition at line 28 of file mysql_query.c.

Referenced by query_buffer_add_long().

#define CMYTH_ULONG_STRLEN   ((sizeof(long)*3)+1)
 

Definition at line 27 of file mysql_query.c.

Referenced by query_buffer_add_ulong().


Function Documentation

cmyth_mysql_query_t* cmyth_mysql_query_create cmyth_database_t  db,
const char *  query_string
 

Allocate a dynamic query string to have parameters added to it.

Parameters:
db database connection object
query_string Query string with ? placemarks for all dynamic parameters, this is NOT copied and must therefore remain valid for the life of the query.

Definition at line 73 of file mysql_query.c.

References query_destroy(), ref_alloc, ref_hold(), ref_release(), and ref_set_destroy().

Referenced by cmyth_get_bookmark_mark(), cmyth_get_bookmark_offset(), cmyth_mysql_get_commbreak_list(), cmyth_mysql_get_guide(), cmyth_mysql_query_commbreak_count(), cmyth_tuner_type_check(), and cmyth_update_bookmark_setting().

int cmyth_mysql_query_param_int cmyth_mysql_query_t query,
int  param
 

Add an integer parameter.

Parameters:
query the query object
param the integer to add

Definition at line 239 of file mysql_query.c.

References cmyth_mysql_query_param_long().

Referenced by cmyth_mysql_get_commbreak_list(), and cmyth_mysql_query_commbreak_count().

int cmyth_mysql_query_param_long cmyth_mysql_query_t query,
long  param
 

Add a long integer parameter.

Parameters:
query the query object
param the integer to add

Definition at line 209 of file mysql_query.c.

References query_begin_next_param(), and query_buffer_add_long().

Referenced by cmyth_get_bookmark_mark(), cmyth_get_bookmark_offset(), cmyth_mysql_query_param_int(), and cmyth_update_bookmark_setting().

int cmyth_mysql_query_param_str cmyth_mysql_query_t query,
const char *  param
 

Add (including adding quotes), and escape a string parameter.

Parameters:
query the query object
param the string to add

Definition at line 283 of file mysql_query.c.

References query_begin_next_param(), query_buffer_add_escape_str(), and query_buffer_add_str().

Referenced by cmyth_get_bookmark_mark(), cmyth_get_bookmark_offset(), cmyth_mysql_get_commbreak_list(), cmyth_mysql_query_commbreak_count(), and cmyth_update_bookmark_setting().

int cmyth_mysql_query_param_uint cmyth_mysql_query_t query,
int  param
 

Add an unsigned integer parameter.

Parameters:
query the query object
param the integer to add

Definition at line 250 of file mysql_query.c.

References cmyth_mysql_query_param_ulong().

Referenced by cmyth_tuner_type_check().

int cmyth_mysql_query_param_ulong cmyth_mysql_query_t query,
unsigned long  param
 

Add an unsigned long integer parameter.

Parameters:
query the query object
param the integer to add

Definition at line 224 of file mysql_query.c.

References query_begin_next_param(), and query_buffer_add_ulong().

Referenced by cmyth_mysql_query_param_uint().

int cmyth_mysql_query_param_unixtime cmyth_mysql_query_t query,
time_t  param
 

Add, and convert a unixtime to mysql date/timestamp.

Parameters:
query the query object
param the time to add

Definition at line 261 of file mysql_query.c.

References query_begin_next_param(), query_buffer_add_long(), and query_buffer_add_str().

Referenced by cmyth_mysql_get_guide().

void cmyth_mysql_query_reset cmyth_mysql_query_t query  ) 
 

Definition at line 101 of file mysql_query.c.

References cmyth_mysql_query_s::buf_used, cmyth_mysql_query_s::source, and cmyth_mysql_query_s::source_pos.

Referenced by query_buffer_check_len().

MYSQL_RES* cmyth_mysql_query_result cmyth_mysql_query_t query  ) 
 

Definition at line 324 of file mysql_query.c.

References cmyth_db_get_connection(), cmyth_dbg(), CMYTH_DBG_ERROR, cmyth_mysql_query_string(), cmyth_mysql_query_s::db, and ref_release().

Referenced by cmyth_get_bookmark_mark(), cmyth_get_bookmark_offset(), cmyth_mysql_get_commbreak_list(), cmyth_mysql_get_guide(), cmyth_mysql_query_commbreak_count(), cmyth_tuner_type_check(), and cmyth_update_bookmark_setting().

char* cmyth_mysql_query_string cmyth_mysql_query_t query  ) 
 

Get the completed query string.

Returns:
If all fields haven't been filled, or there is some other failure this will return NULL, otherwise a string is returned. The returned string must be released by the caller using ref_release().

Definition at line 307 of file mysql_query.c.

References cmyth_mysql_query_s::buf, query_buffer_add_str(), ref_hold(), cmyth_mysql_query_s::source, cmyth_mysql_query_s::source_len, and cmyth_mysql_query_s::source_pos.

Referenced by cmyth_mysql_query_result().

static int query_begin_next_param cmyth_mysql_query_t query  )  [static]
 

Definition at line 174 of file mysql_query.c.

References query_buffer_add(), and cmyth_mysql_query_s::source_pos.

Referenced by cmyth_mysql_query_param_long(), cmyth_mysql_query_param_str(), cmyth_mysql_query_param_ulong(), and cmyth_mysql_query_param_unixtime().

static int query_buffer_add cmyth_mysql_query_t query,
const char *  buf,
int  len
[static]
 

Definition at line 130 of file mysql_query.c.

References cmyth_mysql_query_s::buf, cmyth_mysql_query_s::buf_used, and query_buffer_check_len().

Referenced by query_begin_next_param(), and query_buffer_add_str().

static int query_buffer_add_escape_str cmyth_mysql_query_t query,
const char *  str
[static]
 

Definition at line 148 of file mysql_query.c.

References cmyth_mysql_query_s::buf, cmyth_mysql_query_s::buf_used, cmyth_db_get_connection(), cmyth_mysql_query_s::db, and query_buffer_check_len().

Referenced by cmyth_mysql_query_param_str().

static int query_buffer_add_long cmyth_mysql_query_t query,
long  param
[inline, static]
 

Definition at line 188 of file mysql_query.c.

References CMYTH_LONG_STRLEN, and query_buffer_add_str().

Referenced by cmyth_mysql_query_param_long(), and cmyth_mysql_query_param_unixtime().

static int query_buffer_add_str cmyth_mysql_query_t query,
const char *  str
[inline, static]
 

Definition at line 142 of file mysql_query.c.

References query_buffer_add().

Referenced by cmyth_mysql_query_param_str(), cmyth_mysql_query_param_unixtime(), cmyth_mysql_query_string(), query_buffer_add_long(), and query_buffer_add_ulong().

static int query_buffer_add_ulong cmyth_mysql_query_t query,
long  param
[inline, static]
 

Definition at line 196 of file mysql_query.c.

References CMYTH_ULONG_STRLEN, and query_buffer_add_str().

Referenced by cmyth_mysql_query_param_ulong().

static int query_buffer_check_len cmyth_mysql_query_t query,
int  len
[static]
 

Definition at line 108 of file mysql_query.c.

References cmyth_mysql_query_s::buf, cmyth_mysql_query_s::buf_size, cmyth_mysql_query_s::buf_used, cmyth_mysql_query_reset(), ref_realloc(), and cmyth_mysql_query_s::source_len.

Referenced by query_buffer_add(), and query_buffer_add_escape_str().

static void query_destroy void *  p  )  [static]
 

Internal only! Registered as callback to de-allocate actual buffer if the query is de-allocated.

Parameters:
p pointer to the query data structure

Definition at line 49 of file mysql_query.c.

References cmyth_mysql_query_s::buf, cmyth_mysql_query_s::buf_size, cmyth_mysql_query_s::db, and ref_release().

Referenced by cmyth_mysql_query_create().


Generated on Fri Sep 10 03:13:22 2010 for mvpmc by  doxygen 1.4.6