1
/***************************************************************************
4
* Copyright 2009 Benjamin Ducke, Yann Hamon, OA Digital
5
* <benjamin.ducke@oxfordarch.co.uk>>
6
****************************************************************************/
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Library General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
26
Purpose: This just provides a simple testing binary for the db-easy DBMS interface
27
objects. It is not actually meant to be used as a "proper" program. The db-easy
28
stuff consists of functions that are shared by the mobile/desktop and admin GUIs.
36
#include "db/db_interface.h"
37
#include "db/db_result.h"
39
int main (int argc, char *argv[])
52
/* initialize DB drivers */
55
/* set up options and connect to DBMS */
56
opts = db_options_new ( DB_DRIVER_SQLITE3,
57
"/home/benni/Projekte/OADIGITAL/DigitalRecording/db-prototype/site.oax",
60
fprintf ( stderr, "DB setup error: %s\n", db_error_str () );
64
error = db_connect ( opts );
66
fprintf ( stderr, "DB connection error: %s\n", db_error_str () );
71
/* run a query and save into a result struct */
72
res = db_result_new_from_copy ( opts, "sys_users" );
74
fprintf ( stderr, "DB query error: %s\n", db_error_str () );
77
db_result_set_load_mode ( res, DB_LOAD_DISK );
79
//db_result_force_load_data ( res );
80
intcol = db_result_get_integer_array ( res, "key", &n, -1 );
82
strarr = db_result_get_text_array ( res, "alias", &n );
84
fprintf ( stdout, "rec\tkey\talias\n" );
85
fprintf ( stdout, "---------------------------------\n" );
86
for ( i = 0; i < n; i ++ ) {
87
fprintf ( stdout, "%i\t%i\t%s\n", i + 1, intcol[i], strarr[i] );
90
for ( i = 0; i < n; i ++ ) {
91
if ( strarr[i] != NULL ) {
99
db_result_free ( res );
101
if ( db_error_thrown () ) {
102
fprintf ( stdout, "\nLAST ERROR: %s\n", db_error_str () );
105
error = db_disconnect ( opts );
107
fprintf ( stderr, "DB disconnect error: %s\n", db_error_str () );
111
if ( db_error_thrown () ) {
112
fprintf ( stdout, "\nLAST ERROR: %s\n", db_error_str () );
115
db_options_free ( opts );