// Copyright (c) 2003,2004,2005 Juraj Kolesár #include "tdb.h" /* query {{{ ******************************************************************/ int tdb_query(T_DB *tdb, char * SQL) { //TODO: log - format nicer output log(SQL); if (mysql_real_query(tdb->connection, SQL, strlen(SQL))) { return __LT_ERR; } log("QUERY OK"); return(__LT_OK); } /* }}} */ /* query last id {{{ **********************************************************/ int tdb_query_lastid(T_DB *tdb, char * ID) { long i = mysql_insert_id(tdb->connection); if (i > 0) strcpy(ID, g_strdup_printf("%i",i)); else return(__LT_ERR); return(__LT_OK); } /* }}} */ /* query cell {{{ *************************************************************/ int tdb_query_cell(T_DB *tdb, char *str, char * SQL_select) { MYSQL_ROW row; MYSQL_RES *result; int Fields; int Rows; log("QUERING \"%s\"",SQL_select); if (mysql_real_query(tdb->connection, SQL_select, strlen(SQL_select))) { log("QUERY [FAILED]"); return __LT_ERR; } log("QUERY [OK]"); if (result = mysql_store_result(tdb->connection)) { Fields = mysql_num_fields(result); Rows = mysql_num_rows(result); } else return(__LT_ERR); if ((Rows > 0) && (Fields > 0)) { row = mysql_fetch_row(result); if (row[0] != NULL) strcpy(str, row[0]); else strcpy(str, ""); } mysql_free_result(result); return(__LT_OK); } /* }}} */