blob: e8cc2ad54173048d10f995c91e7d866db16bd3b1 [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**
drheec553b2000-06-02 01:51:20 +000027** @(#) $Id: sqlite.h,v 1.3 2000/06/02 01:51:20 drh Exp $
drh75897232000-05-29 14:26:00 +000028*/
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
drh58b95762000-06-02 01:17:37 +000078** are skipped and the sqlite_exec() function returns the SQLITE_ABORT.
drh75897232000-05-29 14:26:00 +000079**
80** The 4th parameter is an arbitrary pointer that is passed
81** to the callback function as its first parameter.
82**
83** The 2nd parameter to the callback function is the number of
84** columns in the query result. The 3rd parameter is an array
85** of string holding the values for each column. The 4th parameter
86** is an array of strings holding the names of each column.
87**
88** The callback function may be NULL, even for queries. A NULL
89** callback is not an error. It just means that no callback
90** will be invoked.
91**
92** If an error occurs while parsing or evaluating the SQL (but
93** not while executing the callback) then an appropriate error
94** message is written into memory obtained from malloc() and
95** *errmsg is made to point to that message. If errmsg==NULL,
96** then no error message is ever written. The return value is
drh58b95762000-06-02 01:17:37 +000097** SQLITE_ERROR if an error occurs.
98**
99** If the query could not be executed because a database file is
100** locked or busy, then this function returns SQLITE_BUSY. If
101** the query could not be executed because a file is missing or
102** has incorrect permissions, this function returns SQLITE_ERROR.
drh75897232000-05-29 14:26:00 +0000103*/
104int sqlite_exec(
105 sqlite*, /* An open database */
106 char *sql, /* SQL to be executed */
107 sqlite_callback, /* Callback function */
108 void *, /* 1st argument to callback function */
109 char **errmsg /* Error msg written here */
110);
111
drh58b95762000-06-02 01:17:37 +0000112/*
113** Return values fro sqlite_exec()
114*/
115#define SQLITE_OK 0 /* Successful result */
116#define SQLITE_INTERNAL 1 /* An internal logic error in SQLite */
117#define SQLITE_ERROR 2 /* SQL error or missing database */
drheec553b2000-06-02 01:51:20 +0000118#define SQLITE_PERM 3 /* Access permission denied */
119#define SQLITE_ABORT 4 /* Callback routine requested an abort */
120#define SQLITE_BUSY 5 /* One or more database files are locked */
121#define SQLITE_NOMEM 6 /* A malloc() failed */
122#define SQLITE_READONLY 7 /* Attempt to write a readonly database */
123
drh58b95762000-06-02 01:17:37 +0000124
drh75897232000-05-29 14:26:00 +0000125
126/* This function returns true if the given input string comprises
127** one or more complete SQL statements.
128**
129** The algorithm is simple. If the last token other than spaces
130** and comments is a semicolon, then return true. otherwise return
131** false.
132*/
133int sqlite_complete(const char *sql);
134
135#endif /* _SQLITE_H_ */