summaryrefslogtreecommitdiff
path: root/rpmdb/tsql.c
blob: 74bcd1cf672f2d0788d1634c42d431ad29475fd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <sqlite3.h>

#include "sqlite.c"

static int sql_query(sqlite3 *db, const char *cmd)
{
    SCP_t scp = scpNew();
    const char * zTail;
    int rc;
    int i;

fprintf(stderr, "*** %s:\n%s\n", __FUNCTION__, cmd);

#if 0
    rc = sqlite3_prepare(db, cmd, strlen(cmd), &scp->pStmt, &zTail);
    if (rc) fprintf(stderr, "prepare: %d %s\n", rc, sqlite3_errmsg(db));

    rc = sql_step(db, scp);
#else
    rc = sqlite3_get_table(db, cmd,
        &scp->av, &scp->nr, &scp->nc, &scp->pzErrmsg);
    if (rc) fprintf(stderr, "get_table: %d %s\n", rc, sqlite3_errmsg(db));

fprintf(stderr, "%s: DONE scp %p [%d:%d] av %p avlen %p nr %d nc %d\n", __FUNCTION__, scp, scp->ac, scp->nalloc, scp->av, scp->avlen, scp->nr, scp->nc);

    fprintf(stderr, "\tav[0] %p %s\n", scp->av[0], scp->av[0]);
    for (i = 1; i < scp->nr; i++) {
	fprintf(stderr, "\tav[%d] %p %d\n", i, scp->av[i], *(int *)scp->av[i]);
    }
#endif

    scp = scpReset(scp);

    return rc;
}

static const char *dbname = "/var/lib/rpm/Packages";
static const char *qcmd = "SELECT key from 'Packages';";

int main(int argc, char **argv)
{
  sqlite3 *db;
  int rc;

  rc = sqlite3_open(dbname, &db);
  if (rc) {
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    exit(1);
  }

  rc = sql_query(db, qcmd);

  sqlite3_close(db);

  return 0;
}