File: [Platon] / tucniak / db / tdb_table.c (download)
Revision 1.1.1.1 (vendor branch), Fri Nov 11 16:08:26 2005 UTC (18 years, 5 months ago) by koli
Changes since 1.1: +0 -0
lines
Initial import
|
// Copyright (c) 2003,2004,2005 Juraj Kolesár <koli@koli.sk>
#include "tdb.h"
/* fill {{{ *******************************************************************/
int tdb_table_fill(T_DB *tdb, T_MATRIX *matrix, char * SQL_select) {
T_ROW *t_row = NULL;
MYSQL_ROW db_row;
int Fields = 0;
int Rows = 0;
register int col, row;
matrix->table = NULL;
//TODO: this should be not here, check by next compilation
if (mysql_real_query(tdb->connection, SQL_select, strlen(SQL_select))) {
return __LT_ERR;
}
log("%s", SQL_select);
//TODO: remove, or format better this log
if (matrix->memory = mysql_store_result(tdb->connection)) {
Fields = mysql_num_fields(matrix->memory);
Rows = mysql_num_rows(matrix->memory);
} else return __LT_ERR;
for (row=0; row < Rows; row++) {
db_row = mysql_fetch_row(matrix->memory);
for (col=0; col < Fields; col++) {
t_row = g_slist_append(t_row, db_row[col]);
}
matrix->table = g_list_append(matrix->table, t_row);
t_row = NULL;
}
return(Rows);
}
/* }}} */
/* free {{{ *******************************************************************/
int tdb_table_free (T_MATRIX *matrix) {
mysql_free_result(matrix->memory);
g_list_free(matrix->table);
matrix->table = NULL;
return(0);
}
/* }}} */
Platon Group <platon@platon.org> http://platon.org/
|