~foxtrotgps-team/foxtrotgps/trunk

« back to all changes in this revision

Viewing changes to src/util.c

  • Committer: Joshua Judson Rosen
  • Date: 2009-09-26 02:35:15 UTC
  • Revision ID: rozzin@geekspace.com-20090926023515-yxl5sg1a45gupuc8
Imported from tangogps-0.9.7 tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "util.h"
 
2
 
 
3
 
 
4
#include <glib.h>
 
5
#include <glib/gprintf.h>
 
6
#include <stdio.h>
 
7
#include <sqlite3.h>
 
8
#include <stdlib.h> 
 
9
 
 
10
int
 
11
sql_execute(char *db_name, char *sql, int (*cb_func)(void*,int,char**,char**))
 
12
{
 
13
        sqlite3 *db;
 
14
        char *errmsg = 0;
 
15
        int rc;
 
16
        int result = 0;
 
17
        
 
18
        printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
19
 
 
20
 
 
21
        rc = sqlite3_open(db_name, &db);
 
22
        if( rc ){
 
23
                fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
 
24
                sqlite3_close(db);
 
25
                result = -1;
 
26
        }
 
27
        else
 
28
        {
 
29
                rc = sqlite3_exec(db, sql, cb_func, 0, &errmsg);
 
30
        }
 
31
        
 
32
        if( rc!=SQLITE_OK ){
 
33
                fprintf(stderr, "SQL error: %s\n", errmsg);
 
34
                sqlite3_free(errmsg);
 
35
                result = 1;
 
36
        }
 
37
  
 
38
        sqlite3_close(db);
 
39
        return result;
 
40
}