blob: 26b48746ad724a4968fe2d1c44459c1e4e585b4d [file] [log] [blame]
drh75897232000-05-29 14:26:00 +00001/*
2** Copyright (c) 1999, 2000 D. Richard Hipp
3**
4** This program is free software; you can redistribute it and/or
5** modify it under the terms of the GNU General Public
6** License as published by the Free Software Foundation; either
7** version 2 of the License, or (at your option) any later version.
8**
9** This program is distributed in the hope that it will be useful,
10** but WITHOUT ANY WARRANTY; without even the implied warranty of
11** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12** General Public License for more details.
13**
14** You should have received a copy of the GNU General Public
15** License along with this library; if not, write to the
16** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17** Boston, MA 02111-1307, USA.
18**
19** Author contact information:
20** drh@hwaci.com
21** http://www.hwaci.com/drh/
22**
23*************************************************************************
24** This header file defines the interface that the sqlite library
25** presents to client programs.
26**
27** @(#) $Id: sqlite.h,v 1.1 2000/05/29 14:26:01 drh Exp $
28*/
29#ifndef _SQLITE_H_
30#define _SQLITE_H_
31
32/*
33** Each open sqlite database is represented by an instance of the
34** following opaque structure.
35*/
36typedef struct sqlite sqlite;
37
38/*
39** A function to open a new sqlite database.
40**
41** If the database does not exist and mode indicates write
42** permission, then a new database is created. If the database
43** does not exist and mode does not indicate write permission,
44** then the open fails, an error message generated (if errmsg!=0)
45** and the function returns 0.
46**
47** If mode does not indicates user write permission, then the
48** database is opened read-only.
49**
50** The Truth: As currently implemented, all databases are opened
51** for writing all the time. Maybe someday we will provide the
52** ability to open a database readonly. The mode parameters is
53** provide in anticipation of that enhancement.
54*/
55sqlite *sqlite_open(const char *filename, int mode, char **errmsg);
56
57/*
58** A function to close the database.
59**
60** Call this function with a pointer to a structure that was previously
61** returned from sqlite_open() and the corresponding database will by closed.
62*/
63void sqlite_close(sqlite *);
64
65/*
66** The type for a callback function.
67*/
68typedef int (*sqlite_callback)(void*,int,char**, char**);
69
70/*
71** A function to executes one or more statements of SQL.
72**
73** If one or more of the SQL statements are queries, then
74** the callback function specified by the 3rd parameter is
75** invoked once for each row of the query result. This callback
76** should normally return 0. If the callback returns a non-zero
77** value then the query is aborted, all subsequent SQL statements
78** are skipped and the sqlite_exec() function returns the same
79** value that the callback returned.
80**
81** The 4th parameter is an arbitrary pointer that is passed
82** to the callback function as its first parameter.
83**
84** The 2nd parameter to the callback function is the number of
85** columns in the query result. The 3rd parameter is an array
86** of string holding the values for each column. The 4th parameter
87** is an array of strings holding the names of each column.
88**
89** The callback function may be NULL, even for queries. A NULL
90** callback is not an error. It just means that no callback
91** will be invoked.
92**
93** If an error occurs while parsing or evaluating the SQL (but
94** not while executing the callback) then an appropriate error
95** message is written into memory obtained from malloc() and
96** *errmsg is made to point to that message. If errmsg==NULL,
97** then no error message is ever written. The return value is
98** non-zero if an error occurs.
99*/
100int sqlite_exec(
101 sqlite*, /* An open database */
102 char *sql, /* SQL to be executed */
103 sqlite_callback, /* Callback function */
104 void *, /* 1st argument to callback function */
105 char **errmsg /* Error msg written here */
106);
107
108
109/* This function returns true if the given input string comprises
110** one or more complete SQL statements.
111**
112** The algorithm is simple. If the last token other than spaces
113** and comments is a semicolon, then return true. otherwise return
114** false.
115*/
116int sqlite_complete(const char *sql);
117
118#endif /* _SQLITE_H_ */