Macros | Functions
test1.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

int myvfs_init (void)
 
static int callback (void *junk __attribute__((unused)), int cnt, char **vals, char **col_name)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

#define _GNU_SOURCE

Definition at line 1 of file test1.c.

Function Documentation

static int callback ( void *junk   __attribute__(unused),
int  cnt,
char **  vals,
char **  col_name 
)
static

Definition at line 8 of file test1.c.

9 {
10  int i = 0;
11  printf("\n");
12  for (i = 0; i < cnt; ++i) {
13  if (vals[i]) {
14  printf("%s: %s\n", col_name[i], vals[i]);
15  }
16  else {
17  printf("%s: %s\n", col_name[i], "NULL");
18  }
19  }
20  return 0;
21 }
int main ( int  argc,
char **  argv 
)

Definition at line 23 of file test1.c.

24 {
25  sqlite3 * db = 0;
26  char * error_msg = 0;
27  int err = 0;
28  if (argc < 2 || argc > 3) {
29  fprintf(stderr, "usage: %s: <db-filename> [<sql-statement>]. If <sql-statement> is omitted take from stdin.\n", argv[0]);
30  exit(1);
31  }
32  myvfs_init();
33  err = sqlite3_open_v2(argv[1], &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, "myvfs");
34  if (err) {
35  fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
36  sqlite3_close(db);
37  exit(1);
38  }
39  if (argc == 3) {
40  err = sqlite3_exec(db, argv[2], callback, 0, &error_msg);
41  }
42  else {
43  char * buf = 0;
44  size_t n = 0;
45  getline(&buf, &n, stdin);
46  err = sqlite3_exec(db, buf, callback, 0, &error_msg);
47  free(buf);
48  }
49  if (err != SQLITE_OK) {
50  fprintf(stderr, "SQL error: %s\n", error_msg);
51  sqlite3_free(error_msg);
52  }
53  sqlite3_close(db);
54  return 0;
55 }
static int callback(void *junk __attribute__((unused)), int cnt, char **vals, char **col_name)
Definition: test1.c:8
int myvfs_init(void)
Definition: myvfs.c:1748
int myvfs_init ( void  )

Definition at line 1748 of file myvfs.c.

1749 {
1750  /*
1751  ** The following macro defines an initializer for an sqlite3_vfs object.
1752  ** The name of the VFS is NAME. The pAppData is a pointer to a pointer
1753  ** to the "finder" function. (pAppData is a pointer to a pointer because
1754  ** silly C90 rules prohibit a void* from being cast to a function pointer
1755  ** and so we have to go through the intermediate pointer to avoid problems
1756  ** when compiling with -pedantic-errors on GCC.)
1757  **
1758  ** The FINDER parameter to this macro is the name of the pointer to the
1759  ** finder-function. The finder-function returns a pointer to the
1760  ** sqlite_io_methods object that implements the desired locking
1761  ** behaviors. See the division above that contains the IOMETHODS
1762  ** macro for addition information on finder-functions.
1763  **
1764  ** Most finders simply return a pointer to a fixed sqlite3_io_methods
1765  ** object. But the "autolockIoFinder" available on MacOSX does a little
1766  ** more than that; it looks at the filesystem type that hosts the
1767  ** database file and tries to choose an locking method appropriate for
1768  ** that filesystem time.
1769  */
1770 #define UNIXVFS(VFSNAME, FINDER) { \
1771  1, /* iVersion */ \
1772  sizeof(unixFile), /* szOsFile */ \
1773  MAX_PATHNAME, /* mxPathname */ \
1774  0, /* pNext */ \
1775  VFSNAME, /* zName */ \
1776  (void*)&FINDER, /* pAppData */ \
1777  unixOpen, /* xOpen */ \
1778  unixDelete, /* xDelete */ \
1779  unixAccess, /* xAccess */ \
1780  unixFullPathname, /* xFullPathname */ \
1781  unixDlOpen, /* xDlOpen */ \
1782  unixDlError, /* xDlError */ \
1783  unixDlSym, /* xDlSym */ \
1784  unixDlClose, /* xDlClose */ \
1785  unixRandomness, /* xRandomness */ \
1786  unixSleep, /* xSleep */ \
1787  unixCurrentTime, /* xCurrentTime */ \
1788  unixGetLastError, /* xGetLastError */ \
1789  /* unixCurrentTimeInt64, v2, xCurrentTimeInt64 */ \
1790  /* unixSetSystemCall, v3, xSetSystemCall */ \
1791  /* unixGetSystemCall, v3, xGetSystemCall */ \
1792  /* unixNextSystemCall, v3, xNextSystemCall */ \
1793  }
1794  /*
1795  ** All default VFSes for unix are contained in the following array.
1796  **
1797  ** Note that the sqlite3_vfs.pNext field of the VFS object is modified
1798  ** by the SQLite core when the VFS is registered. So the following
1799  ** array cannot be const.
1800  */
1801  static sqlite3_vfs aVfs[] = {
1802  UNIXVFS("myvfs", nolockIoFinder),
1803  };
1804  unsigned int i; /* Loop counter */
1805  /* Double-check that the aSyscall[] array has been constructed
1806  ** correctly. See ticket [bb3a86e890c8e96ab] */
1807  assert(ArraySize(aSyscall) == 16);
1808  /* Register all VFSes defined in the aVfs[] array */
1809  for (i = 0; i < (sizeof(aVfs) / sizeof(sqlite3_vfs)); i++) {
1810  sqlite3_vfs_register(&aVfs[i], i == 0);
1811  }
1812  return SQLITE_OK;
1813 }
static const sqlite3_io_methods *(*const nolockIoFinder)(const char *, unixFile *p)
Definition: myvfs.c:369
#define UNIXVFS(VFSNAME, FINDER)
#define ArraySize(X)
Definition: myvfs.c:19
static struct unix_syscall aSyscall[]