dbd/common.h

Sun, 13 Jun 2010 13:20:03 +0000

author
nrich@ii.net
date
Sun, 13 Jun 2010 13:20:03 +0000
changeset 38
627506d80e5b
parent 33
6c64c45e7d8f
permissions
-rw-r--r--

Fix bug in statemnt dealloc in psql driver

1
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
1 #include <string.h>
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
2 #include <stdio.h>
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
3 #include <stdlib.h>
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
4
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
5 #include <lua.h>
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
6 #include <lauxlib.h>
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
7 #include <lualib.h>
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
8
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
9 #if !defined(LUA_VERSION_NUM) || (LUA_VERSION_NUM < 501)
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
10 #include <compat-5.1.h>
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
11 #endif
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
12
33
6c64c45e7d8f * Fix MySQL date/time types
nrich@ii.net
parents: 22
diff changeset
13 #ifdef _WIN32
6c64c45e7d8f * Fix MySQL date/time types
nrich@ii.net
parents: 22
diff changeset
14 #define LUA_EXPORT __declspec(dllexport)
6c64c45e7d8f * Fix MySQL date/time types
nrich@ii.net
parents: 22
diff changeset
15 #else
6c64c45e7d8f * Fix MySQL date/time types
nrich@ii.net
parents: 22
diff changeset
16 #define LUA_EXPORT
6c64c45e7d8f * Fix MySQL date/time types
nrich@ii.net
parents: 22
diff changeset
17 #endif
6c64c45e7d8f * Fix MySQL date/time types
nrich@ii.net
parents: 22
diff changeset
18
6c64c45e7d8f * Fix MySQL date/time types
nrich@ii.net
parents: 22
diff changeset
19 #ifdef _MSC_VER /* all MS compilers define this (version) */
6c64c45e7d8f * Fix MySQL date/time types
nrich@ii.net
parents: 22
diff changeset
20 #define snprintf _snprintf
6c64c45e7d8f * Fix MySQL date/time types
nrich@ii.net
parents: 22
diff changeset
21 #endif
6c64c45e7d8f * Fix MySQL date/time types
nrich@ii.net
parents: 22
diff changeset
22
2
c4f02fc67e5a Cleanup and commenting
nrich@ii.net
parents: 1
diff changeset
23 /*
c4f02fc67e5a Cleanup and commenting
nrich@ii.net
parents: 1
diff changeset
24 *
c4f02fc67e5a Cleanup and commenting
nrich@ii.net
parents: 1
diff changeset
25 * Table construction helper functions
c4f02fc67e5a Cleanup and commenting
nrich@ii.net
parents: 1
diff changeset
26 *
c4f02fc67e5a Cleanup and commenting
nrich@ii.net
parents: 1
diff changeset
27 * LUA_PUSH_ATTRIB_* creates string indexed (hashmap)
33
6c64c45e7d8f * Fix MySQL date/time types
nrich@ii.net
parents: 22
diff changeset
28 * LUA_PUSH_ARRAY_* creates integer indexed (array)
2
c4f02fc67e5a Cleanup and commenting
nrich@ii.net
parents: 1
diff changeset
29 *
c4f02fc67e5a Cleanup and commenting
nrich@ii.net
parents: 1
diff changeset
30 */
1
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
31
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
32 #define LUA_PUSH_ATTRIB_INT(n, v) \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
33 lua_pushstring(L, n); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
34 lua_pushinteger(L, v); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
35 lua_rawset(L, -3);
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
36
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
37 #define LUA_PUSH_ATTRIB_FLOAT(n, v) \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
38 lua_pushstring(L, n); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
39 lua_pushnumber(L, v); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
40 lua_rawset(L, -3);
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
41
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
42 #define LUA_PUSH_ATTRIB_STRING(n, v) \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
43 lua_pushstring(L, n); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
44 lua_pushstring(L, v); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
45 lua_rawset(L, -3);
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
46
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
47 #define LUA_PUSH_ATTRIB_BOOL(n, v) \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
48 lua_pushstring(L, n); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
49 lua_pushboolean(L, v); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
50 lua_rawset(L, -3);
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
51
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
52 #define LUA_PUSH_ATTRIB_NIL(n) \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
53 lua_pushstring(L, n); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
54 lua_pushnil(L); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
55 lua_rawset(L, -3);
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
56
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
57
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
58
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
59 #define LUA_PUSH_ARRAY_INT(n, v) \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
60 lua_pushinteger(L, v); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
61 lua_rawseti(L, -2, n); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
62 n++;
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
63
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
64 #define LUA_PUSH_ARRAY_FLOAT(n, v) \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
65 lua_pushnumber(L, v); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
66 lua_rawseti(L, -2, n); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
67 n++;
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
68
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
69 #define LUA_PUSH_ARRAY_STRING(n, v) \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
70 lua_pushstring(L, v); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
71 lua_rawseti(L, -2, n); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
72 n++;
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
73
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
74 #define LUA_PUSH_ARRAY_BOOL(n, v) \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
75 lua_pushboolean(L, v); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
76 lua_rawseti(L, -2, n); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
77 n++;
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
78
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
79 #define LUA_PUSH_ARRAY_NIL(n) \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
80 lua_pushnil(L); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
81 lua_rawseti(L, -2, n); \
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
82 n++;
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
83
2
c4f02fc67e5a Cleanup and commenting
nrich@ii.net
parents: 1
diff changeset
84 /*
c4f02fc67e5a Cleanup and commenting
nrich@ii.net
parents: 1
diff changeset
85 *
4
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
86 * Describes SQL to Lua API type conversions
2
c4f02fc67e5a Cleanup and commenting
nrich@ii.net
parents: 1
diff changeset
87 *
c4f02fc67e5a Cleanup and commenting
nrich@ii.net
parents: 1
diff changeset
88 */
1
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
89
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
90 typedef enum lua_push_type {
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
91 LUA_PUSH_NIL = 0,
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
92 LUA_PUSH_INTEGER,
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
93 LUA_PUSH_NUMBER,
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
94 LUA_PUSH_STRING,
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
95 LUA_PUSH_BOOLEAN,
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
96
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
97 LUA_PUSH_MAX
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
98 } lua_push_type_t;
408291a6eb3e Initial import.
nrich@ii.net
parents:
diff changeset
99
4
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
100 /*
17
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
101 * used for placeholder translations
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
102 * from '?' to the .\d{4}
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
103 */
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
104 #define MAX_PLACEHOLDERS 9999
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
105 #define MAX_PLACEHOLDER_SIZE (1+4) /* .\d{4} */
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
106
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
107 /*
4
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
108 *
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
109 * Common error strings
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
110 * defined here for consistency in driver implementations
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
111 *
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
112 */
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
113
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
114 #define DBI_ERR_CONNECTION_FAILED "Failed to connect to database: %s"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
115 #define DBI_ERR_DB_UNAVAILABLE "Database not available"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
116 #define DBI_ERR_EXECUTE_INVALID "Execute called on a closed or invalid statement"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
117 #define DBI_ERR_EXECUTE_FAILED "Execute failed %s"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
118 #define DBI_ERR_FETCH_INVALID "Fetch called on a closed or invalid statement"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
119 #define DBI_ERR_FETCH_FAILED "Fetch failed %s"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
120 #define DBI_ERR_PARAM_MISCOUNT "Statement expected %d parameters but received %d"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
121 #define DBI_ERR_BINDING_PARAMS "Error binding statement parameters: %s"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
122 #define DBI_ERR_BINDING_EXEC "Error executing statement parameters: %s"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
123 #define DBI_ERR_FETCH_NO_EXECUTE "Fetch called before execute"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
124 #define DBI_ERR_BINDING_RESULTS "Error binding statement results: %s"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
125 #define DBI_ERR_UNKNOWN_PUSH "Unknown push type in result set"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
126 #define DBI_ERR_ALLOC_STATEMENT "Error allocating statement handle: %s"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
127 #define DBI_ERR_PREP_STATEMENT "Error preparing statement handle: %s"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
128 #define DBI_ERR_INVALID_PORT "Invalid port: %d"
c50b0e6f25d6 Clean up error messages for consistency.
nrich@ii.net
parents: 2
diff changeset
129 #define DBI_ERR_ALLOC_RESULT "Error allocating result set: %s"
14
98192b7d4e89 Add DB2 driver module.
nrich@ii.net
parents: 10
diff changeset
130 #define DBI_ERR_DESC_RESULT "Error describing result set: %s"
10
3aa8a37a3dd8 Added new typechecks and errors
nrich@ii.net
parents: 4
diff changeset
131 #define DBI_ERR_BINDING_TYPE_ERR "Unknown or unsupported type `%s'"
21
7956401a0c5e Added the statement:affected() and statement:rowcount() methods.
nrich@ii.net
parents: 17
diff changeset
132 #define DBI_ERR_INVALID_STATEMENT "Invalid statement handle"
7956401a0c5e Added the statement:affected() and statement:rowcount() methods.
nrich@ii.net
parents: 17
diff changeset
133 #define DBI_ERR_NOT_IMPLEMENTED "Method %s.%s is not implemented"
22
fd78e9cdc6e9 * Added the connection:quote() method
nrich@ii.net
parents: 21
diff changeset
134 #define DBI_ERR_QUOTING_STR "Error quoting string: %s"
17
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
135
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
136 /*
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
137 * convert string to lower case
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
138 */
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
139 const char *strlower(char *in);
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
140
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
141 /*
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
142 * replace '?' placeholders with .\d+ placeholders
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
143 * to be compatible with the native driver API
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
144 */
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
145 char *replace_placeholders(lua_State *L, char native_prefix, const char *sql);
21c4feaeafe7 Added initial Oracle driver support - functionality is complete, but may be too buggy in its current state for any serious use.
nrich@ii.net
parents: 14
diff changeset
146

mercurial