~ubuntu-branches/ubuntu/karmic/edbrowse/karmic

« back to all changes in this revision

Viewing changes to dbapi.h

  • Committer: Bazaar Package Importer
  • Author(s): Kapil Hari Paranjape
  • Date: 2007-05-09 07:33:04 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070509073304-ywptg9g6iiitsg17
Tags: 3.2.1-1
* New upstream version (3.2.1). Closes: #421451.
  - can fetch and execute a local javascript file
    if required by local html file.
  - provide COPYING and CHANGES files.
* debian/rules:
  - add CHANGES to dh_installchangelogs line.
  - add dh_installman entry to install the man page.
* debian/copyright: updated to include the COPYING file.
* debian/edbrowse.1: added a basic man page.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* dbapi.h: header file for the generic edbrowse sql database API */
 
2
 
 
3
/* Number of returns may as well be the max number of columns we can manage in edbrowse */
 
4
#define NUMRETS MAXTCOLS
 
5
 
 
6
#define COLNAMELEN 40 /* length of column or table or database name */
 
7
#define NUMCURSORS 8 /* number of open cursors */
 
8
#define STRINGLEN 1000 /* longest string in the database */
 
9
 
 
10
/* constants to help format dates and times */
 
11
#define YEARFIRST 1 /* when printing dates */
 
12
#define DTDELIMIT 2 /* delimit datetime fields */
 
13
#define DTCRUNCH 4 /* leave off century or seconds */
 
14
#define DTAMPM 8 /* print with AM PM notation */
 
15
 
 
16
/* null values and isnull macros */
 
17
#define nullint 0x7fff0000
 
18
#define nulldate nullint
 
19
#define nulltime nullint
 
20
#define nullmoney nullint
 
21
#define nullfloat (0x7fff*65536.0)
 
22
#define nullstring ((void*)0)
 
23
#define nullchar '\0'
 
24
 
 
25
/* null test, for ints and dates and times, not floats or strings or chars */
 
26
#define isnull(x) ((x) == nullint)
 
27
#define isnotnull(x) ((x) != nullint)
 
28
#define isnullstring(s) (!(s) || !*(s))
 
29
#define isnotnullstring(s) ((s) && *(s))
 
30
#define isnullfloat(x) ((x) == nullfloat)
 
31
#define isnotnullfloat(x) ((x) != nullfloat)
 
32
 
 
33
/* useful C data types */
 
34
/* long and float together */
 
35
typedef union {
 
36
    long l;
 
37
    double f;
 
38
    void *ptr;
 
39
} LF;
 
40
 
 
41
typedef void (*fnptr)(); /* function pointer */
 
42
typedef long date;
 
43
typedef long interval;
 
44
typedef long money;
 
45
 
 
46
#define sql_debug (debugLevel >= 3)
 
47
extern const char *sql_debuglog; /* log of debug prints */
 
48
extern const char *sql_database; /* name of current database */
 
49
 
 
50
/* Arrays that hold the return values from a select statement,
 
51
fetch, or any other function that has multiple returns. */
 
52
extern int rv_numRets; /* number of returned values */
 
53
extern char rv_type[NUMRETS+1]; /* datatypes of returned values */
 
54
extern char rv_name[NUMRETS+1][COLNAMELEN]; /* column names */
 
55
extern LF  rv_data[NUMRETS]; /* the returned values */
 
56
 
 
57
/* status variables, set by an SQL statement */
 
58
extern int rv_lastStatus; /* status of last sql_exec command */
 
59
extern int rv_vendorStatus; /* vendor-specific error code */
 
60
extern int rv_stmtOffset; /* offset of syntax error within sql statement */
 
61
extern int rv_lastNrows; /* number of rows affected */
 
62
extern int rv_lastSerial; /* serial number generated by last insert */
 
63
extern int rv_lastRowid; /* rowid generated by last insert */
 
64
extern void *rv_blobLoc; /* point to blob in memory */
 
65
extern int rv_blobSize; /* size of blob fetched */
 
66
extern const char *rv_blobFile;
 
67
extern bool rv_blobAppend;
 
68
 
 
69
 
 
70
/*********************************************************************
 
71
The ODBC error codes are strings (somewhat inconvenient),
 
72
subject to change, and supernumerous.
 
73
In other words, the application usually doesn't require this level of
 
74
granularity, except in the error messages, which are all handled by odbc.c.
 
75
More often, the application wants to trap an integrity error,
 
76
such as a check constraint violation, and abort on anything else.
 
77
To this end, we have created our own SQL exception codes, listed below.
 
78
By designating a couple of these exception codes,
 
79
the application can direct error recovery at a high level.
 
80
*********************************************************************/
 
81
 
 
82
#define EXCSQLMISC 1 /* miscelaneous SQL errors not covered below */
 
83
#define EXCSYNTAX 2 /* syntax error in SQL statement */
 
84
#define EXCFILENAME 3 /* this filename cannot be used by SQL */
 
85
#define EXCCONVERT 4 /* cannot convert/compare the columns/constants in the SQL statement */
 
86
#define EXCSUBSCRIPT 5 /* bad string subscripting */
 
87
#define EXCROWIDUSE 6 /* bad use of the rowid pseudo-column */
 
88
#define EXCBLOBUSE 7 /* bad use of a blob column */
 
89
#define EXCAGGREGATEUSE 8 /* bad use of aggregate operators or columns */
 
90
#define EXCVIEWUSE 9 /* bad use of a view */
 
91
#define EXCTEMPTABLEUSE 10 /* bad use of a temp table */
 
92
#define EXCTRUNCATE 11 /* data truncated, into the database or into local buffers */
 
93
#define EXCCROSSDB 12 /* operation cannot cross databases */
 
94
#define EXCDBCORRUPT 13 /* database is corrupted, time to panic. */
 
95
#define EXCINTERRUPT 14 /* user interrupted the query */
 
96
#define EXCNOCONNECT 15 /* error in the connection to the database */
 
97
#define EXCNODB 16 /* no database selected */
 
98
#define EXCNOTABLE 17 /* no such table */
 
99
#define EXCDUPTABLE 18 /* duplicate table */
 
100
#define EXCAMBTABLE 19 /* ambiguous table */
 
101
#define EXCNOCOLUMN 20 /* no such column */
 
102
#define EXCDUPCOLUMN 21 /* duplicate column */
 
103
#define EXCAMBCOLUMN 22 /* ambiguous column */
 
104
#define EXCNOINDEX 23 /* no index */
 
105
#define EXCDUPINDEX 24 /* duplicate index */
 
106
#define EXCNOCONSTRAINT 25 /* no constraint */
 
107
#define EXCDUPCONSTRAINT 26 /* duplicate constraint */
 
108
#define EXCNOSPROC 27 /* no stored procedure */
 
109
#define EXCDUPSPROC 28 /* duplicate stored procedure */
 
110
#define EXCNOSYNONYM 29 /* no such synonym */
 
111
#define EXCDUPSYNONYM 30 /* duplicate synonym */
 
112
#define EXCNOKEY 31 /* table has no primary or unique key */
 
113
#define EXCDUPKEY 32 /* duplicated primary or unique key */
 
114
#define EXCNOCURSOR 33 /* cursor not specified, or not available */
 
115
#define EXCDUPCURSOR 34 /* duplicating a cursor */
 
116
#define EXCRESOURCE 35 /* engine lacks the resources needed to complete this query */
 
117
#define EXCCHECK 36 /* check constrain violated */
 
118
#define EXCREFINT 37 /* referential integrity violated */
 
119
#define EXCMANAGETRANS 38 /* cannot manage or complete the transaction */
 
120
#define EXCLONGTRANS 39 /* long transaction, too much log data generated */
 
121
#define EXCNOTINTRANS 40 /* this operation requires a transaction */
 
122
#define EXCMANAGEBLOB 41 /* cannot open read write close or otherwise manage a blob */
 
123
#define EXCITEMLOCK 42 /* row, table, page, or database is locked, or cannot be locked */
 
124
#define EXCNOTNULLCOLUMN 43 /* inserting null into a not null column */
 
125
#define EXCPERMISSION 44 /* no permission to modify the database in this way */
 
126
#define EXCNOROW 45 /* no current row */
 
127
#define EXCMANYROW 46 /* many rows were found where one was expected */
 
128
#define EXCUNION 47 /* cannot union select statements together */
 
129
#define EXCACTIVE 48 /* an open connection or executing SQL statement prevents this function from running */
 
130
#define EXCREMOTE 49 /* could not run SQL or gather data from the remote host */
 
131
#define EXCWHERECLAUSE 50 /* where clause is semantically unmanageable */
 
132
#define EXCDEADLOCK 51 /* deadlock detected */
 
133
#define EXCARGUMENT 52 /* bad argument to ODBC, such as null pointer */
 
134
#define EXCUNSUPPORTED 53 /* function or capability or option not supported */
 
135
#define EXCTIMEOUT 54 /* timeout before SQL completed */
 
136
#define EXCTRACE 55 /* error tracing SQL statements, or leaving audit trails */
 
137
#define EXCSERIAL 56 /* bad use of serial column */
 
138
 
 
139
 
 
140
/*********************************************************************
 
141
Function prototypes.
 
142
*********************************************************************/
 
143
 
 
144
void sql_exclist(const short *list) ;
 
145
void sql_exception(int errnum) ;
 
146
void sql_disconnect(void) ;
 
147
void sql_connect(const char *db, const char *login, const char *pw) ;
 
148
void sql_begTrans(void) ;
 
149
void sql_commitWork(void) ;
 
150
void sql_rollbackWork(void) ;
 
151
void sql_deferConstraints(void) ;
 
152
void sql_execNF(const char *stmt) ;
 
153
void sql_exec(const char *stmt, ...) ;
 
154
void retsCopy(bool allstrings, void *first, ...) ;
 
155
int findcol_byname(const char *name) ;
 
156
bool sql_select(const char *stmt, ...) ;
 
157
bool sql_selectNF(const char *stmt, ...) ;
 
158
int sql_selectOne(const char *stmt, ...) ;
 
159
bool sql_proc(const char *stmt, ...) ;
 
160
int sql_procOne(const char *stmt, ...) ;
 
161
int sql_prepare(const char *stmt, ...) ;
 
162
int sql_prepareScrolling(const char *stmt, ...) ;
 
163
void sql_open(int cid) ;
 
164
int sql_prepOpen(const char *stmt, ...) ;
 
165
void sql_close(int cid) ;
 
166
void sql_free( int cid) ;
 
167
void sql_closeFree(int cid) ;
 
168
bool fetchInternal(int cid, long n, int flag, bool remember) ;
 
169
bool sql_fetchFirst(int cid, ...) ;
 
170
bool sql_fetchLast(int cid, ...) ;
 
171
bool sql_fetchNext(int cid, ...) ;
 
172
bool sql_fetchPrev(int cid, ...) ;
 
173
bool sql_fetchAbs(int cid, long rownum, ...) ;
 
174
void sql_blobInsert(const char *tabname, const char *colname, int rowid,
 
175
        const char *filename, void *offset, int length) ;
 
176
void sql_mkload(const char *line, char delim) ;
 
177
void sql_cursorUpdLine(int cid, const char *line) ;
 
178
void sql_cursorDelLine(int cid, int rownum) ;
 
179
void sql_cursorInsLine(int cid, int rownum) ;
 
180
void getPrimaryKey(char *tname, int *part1, int *part2) ;
 
181
 
 
182
/* sourcefile=dbops.c */
 
183
char *lineFormat(const char *line, ...) ;
 
184
char *lineFormatStack( const char *line, LF *argv, va_list *parmv_p) ;
 
185
char *sql_mkunld(char delim) ;
 
186
char *sql_mkinsupd(void) ;
 
187
bool isLeapYear(int year) ;
 
188
date dateEncode(int year, int month, int day) ;
 
189
void dateDecode(date d, int *yp, int *mp, int *dp) ;
 
190
date stringDate(const char *s, bool yearfirst) ;
 
191
char *dateString(date d, int flags) ;
 
192
char *timeString(interval seconds, int flags) ;
 
193
interval stringTime(const char *t) ;
 
194
char *moneyString(money m) ;
 
195
money stringMoney(const char *s) ;
 
196
void syncup_table( const char *table1, const char *table2,
 
197
        const char *keycol, const char *otherclause) ;
 
198