Merge lp:~zorba-coders/zorba/bug-1189784 into lp:zorba/sqlite-module

Proposed by Luis Rodriguez Gonzalez
Status: Merged
Merged at revision: 36
Proposed branch: lp:~zorba-coders/zorba/bug-1189784
Merge into: lp:zorba/sqlite-module
Diff against target: 1369 lines (+340/-226)
33 files modified
src/CMakeLists.txt (+1/-1)
src/sqlite_module.xq (+106/-76)
src/sqlite_module.xq.src/sqlite_module.cpp (+183/-116)
src/sqlite_module.xq.src/sqlite_module.h (+20/-3)
test/Queries/test0.xq (+1/-1)
test/Queries/test1.xq (+1/-1)
test/Queries/test10.xq (+1/-1)
test/Queries/test11.spec (+1/-1)
test/Queries/test11.xq (+1/-1)
test/Queries/test12.spec (+1/-1)
test/Queries/test12.xq (+1/-1)
test/Queries/test13.spec (+1/-1)
test/Queries/test13.xq (+1/-1)
test/Queries/test14.spec (+1/-1)
test/Queries/test14.xq (+1/-1)
test/Queries/test15.spec (+1/-1)
test/Queries/test15.xq (+1/-1)
test/Queries/test16.spec (+1/-1)
test/Queries/test16.xq (+1/-1)
test/Queries/test17.spec (+1/-1)
test/Queries/test17.xq (+1/-1)
test/Queries/test18.xq (+1/-1)
test/Queries/test2.xq (+1/-1)
test/Queries/test3.spec (+1/-1)
test/Queries/test3.xq (+1/-1)
test/Queries/test4.spec (+1/-1)
test/Queries/test4.xq (+1/-1)
test/Queries/test5.spec (+1/-1)
test/Queries/test5.xq (+1/-1)
test/Queries/test6.xq (+1/-1)
test/Queries/test7.xq (+2/-2)
test/Queries/test8.xq (+1/-1)
test/Queries/test9.xq (+1/-1)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug-1189784
Reviewer Review Type Date Requested Status
Luis Rodriguez Gonzalez Approve
Chris Hillery Approve
Review via email: mp+177489@code.launchpad.net

Commit message

JSONiqfication for Sqlite Module Done!

To post a comment you must log in.
Revision history for this message
Chris Hillery (ceejatec) wrote :

Looks good - nice job!

I made three small changes:

1. Moved a <p/> in the metadata() doc to immediately after the leading sentence of the comment.

2. Moved SqliteModule() constructor definition out-of-line.

3. Per mailing list discussion, marked a number of module functions as nondeterministic rather than sequential (per Matthias).

review: Approve
lp:~zorba-coders/zorba/bug-1189784 updated
38. By Chris Hillery

Minor comment fix. Move SqliteModule() constructor out-of-line. Change some
module functions to nondeterministic rather than sequential.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~zorba-coders/zorba/bug-1189784/+merge/177489

Progress dashboard at http://jenkins.lambda.nu/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting criteria failed for the following merge proposals:

https://code.launchpad.net/~zorba-coders/zorba/bug-1189784/+merge/177489 :
Votes: {'Approve': 1, 'Pending': 1, 'Needs commit message': 1}

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue result for https://code.launchpad.net/~zorba-coders/zorba/bug-1189784/+merge/177489

Stage "CommitZorba" failed.

Check console output at http://jenkins.lambda.nu/job/CommitZorba/67/console to view the results.

Revision history for this message
Luis Rodriguez Gonzalez (kuraru) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~zorba-coders/zorba/bug-1189784/+merge/177489

Progress dashboard at http://jenkins.lambda.nu/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue succeeded - proposal merged!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2013-01-24 06:17:00 +0000
3+++ src/CMakeLists.txt 2013-07-30 00:41:26 +0000
4@@ -17,7 +17,7 @@
5 INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}")
6
7 DECLARE_ZORBA_MODULE (
8- URI "http://www.zorba-xquery.com/modules/sqlite"
9+ URI "http://zorba.io/modules/sqlite"
10 VERSION 1.0
11 FILE "sqlite_module.xq"
12 LINK_LIBRARIES "${SQLITE_LIBRARIES}")
13
14=== modified file 'src/sqlite_module.xq'
15--- src/sqlite_module.xq 2013-06-15 19:48:35 +0000
16+++ src/sqlite_module.xq 2013-07-30 00:41:26 +0000
17@@ -1,4 +1,4 @@
18-xquery version "3.0";
19+jsoniq version "1.0";
20
21 (:
22 : Copyright 2012 The FLWOR Foundation.
23@@ -17,15 +17,15 @@
24 :)
25
26 (:~
27- : <p>This module provides functionality to extract, add and modify data
28- : from SQLite databases.</p>
29+ : This module provides functionality to extract, add and modify data
30+ : from SQLite databases.<p/>
31 :
32 : @author Luis Rodgriguez
33 : @library <a href="http://www.sqlite.org/">SQLite</a>
34 : @project DB Drivers/SQLite
35 :)
36
37-module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
38+module namespace s = "http://zorba.io/modules/sqlite";
39 declare namespace an = "http://www.zorba-xquery.com/annotations";
40 declare namespace ver = "http://www.zorba-xquery.com/options/versioning";
41 declare option ver:module-version "1.0";
42@@ -37,21 +37,23 @@
43 :
44 : @return the SQLite database object as xs:anyURI.
45 :
46- : @error s:SQLI0001 if the database name doesn't exist or it couldn't be opened.
47- : @error s:SQLI0008 if a non-in-memory database is requested and the module
48- : is built without filesystem access
49- : @error s:SQLI9999 if there was an internal error inside SQLite library.
50+ : @error s:CANT-OPEN-DB if the database name doesn't exist or it couldn't be
51+ : opened.
52+ : @error s:COMPILED-WITHOUT-DISK-ACCESS if a non-in-memory database is
53+ : requested and the module is built without filesystem access.
54+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside
55+ : SQLite library.
56 :)
57-declare %an:sequential function s:connect(
58+declare %an:nondeterministic function s:connect(
59 $db-name as xs:string
60 ) as xs:anyURI external;
61
62 (:~
63- : Connect to a SQLite database with optional options.
64+ : Connect to a SQLite database with optional options.<p/>
65 : All options are true/false values. Available options are: open-read-only,
66 : open-create, open-no-mutex, and open-shared-cache.
67 :
68- : <p>The options are of the form:
69+ : The options are of the form:
70 : <pre>
71 : {
72 : "open_read_only" : true,
73@@ -59,20 +61,22 @@
74 : ...
75 : }
76 : </pre>
77- : </p>
78+ : <p/>
79 :
80 : @param $db-name the SQLite database name to be opened as xs:string.
81 : @param $options a JSON object containing SQLite connection options.
82 :
83 : @return the SQLite database object as xs:anyURI.
84 :
85- : @error s:SQLI0001 if the databse name doesn't exist or it couldn't be opened.
86- : @error s:SQLI0007 if there is any unknown option specified.
87- : @error s:SQLI0008 if a non-in-memory database is requested and the module
88- : is built without filesystem access
89- : @error s:SQLI9999 if there was an internal error inside SQLite library.
90+ : @error s:CANT-OPEN-DB if the database name doesn't exist or it couldn't be
91+ : opened.
92+ : @error s:UNKNOWN-OPTION if there is any unknown option specified.
93+ : @error s:COMPILED-WITHOUT-DISK-ACCESS if a non-in-memory database is
94+ : requested and the module is built without filesystem access.
95+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
96+ : library.
97 :)
98-declare %an:sequential function s:connect(
99+declare %an:nondeterministic function s:connect(
100 $db-name as xs:string,
101 $options as object()?
102 ) as xs:anyURI external;
103@@ -82,36 +86,40 @@
104 :
105 : @param $conn the SQLite database object as xs:anyURI.
106 :
107- : @return true if the given SQLite database object is connected, false otherwise.
108+ : @return true if the given SQLite database object is connected, false
109+ : otherwise.
110 :
111- : @error s:SQLI0002 if $conn is not a valid SQLite database object.
112- : @error s:SQLI9999 if there was an internal error inside SQLite library.
113+ : @error s:INVALID-SQLITE-OBJECT if $conn is not a valid SQLite database object.
114+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
115+ : library.
116 :)
117-declare %an:sequential function s:is-connected(
118+declare %an:nondeterministic function s:is-connected(
119 $conn as xs:anyURI ) as xs:boolean external;
120
121 (:~
122- : Commits all the pending update operations in this SQLite database.
123+ : Commits all pending update operations in this SQLite database.
124 :
125 : @param $conn the SQLite database object as xs:anyURI.
126 :
127 : @return the passed SQLite object.
128 :
129- : @error s:SQLI0002 if $conn is not a valid SQLite database object.
130- : @error s:SQLI9999 if there was an internal error inside SQLite library.
131+ : @error s:INVALID-SQLITE-OBJECT if $conn is not a valid SQLite database object.
132+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
133+ : library.
134 :)
135 declare %an:sequential function s:commit(
136 $conn as xs:anyURI ) as xs:anyURI external;
137
138 (:~
139- : Rollbacks all the pending update operations in this SQLite database.
140+ : Rollbacks all pending update operations in this SQLite database.
141 :
142 : @param $conn the SQLite database object as xs:anyURI.
143 :
144 : @return the passed SQLite object.
145 :
146- : @error s:SQLI0002 if $conn is not a valid SQLite database object.
147- : @error s:SQLI9999 if there was an internal error inside SQLite library.
148+ : @error s:INVALID-SQLITE-OBJECT if $conn is not a valid SQLite database object.
149+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
150+ : library.
151 :)
152 declare %an:sequential function s:rollback(
153 $conn as xs:anyURI ) as xs:anyURI external;
154@@ -125,34 +133,36 @@
155 :
156 : @return a sequence of JSON objects describing each row returned.
157 :
158- : @error s:SQLI0002 if $conn is not a valid SQLite database object.
159- : @error s:SQLI0003 if $stmnt is not a valid sql command.
160- : @error s:SQLI9999 if there was an internal error inside SQLite library.
161+ : @error s:INVALID-SQLITE-OBJECT if $conn is not a valid SQLite database object.
162+ : @error s:INVALID-SQL-STATEMENT if $stmnt is not a valid sql command.
163+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
164+ : library.
165 :)
166-declare %an:sequential function s:execute-query(
167+declare %an:nondeterministic function s:execute-query(
168 $conn as xs:anyURI,
169 $sqlstr as xs:string ) as object()* external;
170
171 (:~
172- : Executes a update command over an already opened SQLite database object.
173+ : Executes an update command over an already opened SQLite database object.
174 :
175 : @param $conn an already opened SQLite database object as xs:anyURI.
176 : @param $sqlstr the update command to be executed as xs:string.
177 :
178 : @return the amount of rows modified by such update command.
179 :
180- : @error s:SQLI0002 if $conn is not a valid SQLite database object.
181- : @error s:SQLI0003 if $stmnt is not a valid sql command.
182- : @error s:SQLI9999 if there was an internal error inside SQLite library.
183+ : @error s:INVALID-SQLITE-OBJECT if $conn is not a valid SQLite database object.
184+ : @error s:INVALID-SQL-STATEMENT if $stmnt is not a valid sql command.
185+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
186+ : library.
187 :)
188 declare %an:sequential function s:execute-update(
189 $conn as xs:anyURI,
190 $sqlstr as xs:string ) as xs:integer external;
191
192 (:~
193- : Returns the metadata associated to a given prepared SQLite statement.
194+ : Returns the metadata associated to a given prepared SQLite statement.<p/>
195 :
196- : <p>SQLite metadata is returned in the following form:
197+ : SQLite metadata is returned in the following form:
198 : <pre>
199 : {
200 : "columns" :
201@@ -168,37 +178,40 @@
202 : }*]
203 : }
204 : </pre>
205- : </p>
206 :
207- : @param $pstmnt the sql command as xs:anyURI from which metadata will be extracted.
208+ : @param $pstmnt the sql command as xs:anyURI from which metadata will be
209+ : extracted.
210 :
211 : @return a object() with the associated the metadata.
212 :
213- : @error s:SQLI0004 if $pstmnt is not a valid SQLite prepared statement.
214- : @error s:SQLI0009 if no metadata is available (SQLite library compiled without
215- : SQLITE_ENABLE_COLUMN_METADATA).
216- : @error s:SQLI9999 if there was an internal error inside SQLite library.
217+ : @error s:INVALID-PREPARED-STATEMENT if $pstmnt is not a valid SQLite prepared
218+ : statement.
219+ : @error s:UNAVAILABLE-METADATA if no metadata is available (SQLite library
220+ : compiled without SQLITE_ENABLE_COLUMN_METADATA).
221+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
222+ : library.
223 :)
224-declare %an:sequential function s:metadata(
225+declare %an:nondeterministic function s:metadata(
226 $pstmnt as xs:anyURI ) as object() external;
227
228 (:~
229 : Compiles a prepared statement based on an already connected SQLite database
230- : and a string that defines the sql command.
231+ : and a string that defines the sql command.<p/>
232 :
233- : <p>You can use '?' in the sql command as placeholders so you will
234- : be able to bind variables later to such places.</p>
235+ : You can use '?' in the sql command as placeholders so you will
236+ : be able to bind variables later to such places.<p/>
237 :
238 : @param $conn the SQLite database object as xs:anyURI.
239 : @param $stmnt the sql command as xs:string.
240 :
241 : @return a xs:anyURI object representing the prepared statement.
242 :
243- : @error s:SQLI0002 if $conn is not a valid SQLite database object.
244- : @error s:SQLI0003 if $stmnt is not a valid sql command.
245- : @error s:SQLI9999 if there was an internal error inside SQLite library.
246+ : @error s:INVALID-SQLITE-OBJECT if $conn is not a valid SQLite database object.
247+ : @error s:INVALID-SQL-STATEMENT if $stmnt is not a valid sql command.
248+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
249+ : library.
250 :)
251-declare %an:sequential function s:prepare-statement(
252+declare %an:nondeterministic function s:prepare-statement(
253 $conn as xs:anyURI,
254 $stmnt as xs:string ) as xs:anyURI external;
255
256@@ -212,10 +225,12 @@
257 :
258 : @return nothing.
259 :
260- : @error s:SQLI0004 if $pstmnt is not a valid SQLite prepared statement.
261- : @error s:SQLI0005 if $param-num is not a valid position.
262- : @error s:SQLI0007 if $val is not a valid value.
263- : @error s:SQLI9999 if there was an internal error inside SQLite library.
264+ : @error s:INVALID-PREPARED-STATEMENT if $pstmnt is not a valid SQLite prepared
265+ : statement.
266+ : @error s:INVALID-PLACEHOLDER-POSITION if $param-num is not a valid position.
267+ : @error s:INVALID-VALUE if $val is not a valid value.
268+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
269+ : library.
270 :)
271 declare %an:sequential function s:set-value(
272 $pstmnt as xs:anyURI,
273@@ -231,9 +246,11 @@
274 :
275 : @return nothing.
276 :
277- : @error s:SQLI0004 if $pstmnt is not a valid SQLite prepared statement.
278- : @error s:SQLI0005 if $param-num is not a valid position.
279- : @error s:SQLI9999 if there was an internal error inside SQLite library.
280+ : @error s:INVALID-PREPARED-STATEMENT if $pstmnt is not a valid SQLite prepared
281+ : statement.
282+ : @error s:INVALID-PLACEHOLDER-POSITION if $param-num is not a valid position.
283+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
284+ : library.
285 :)
286 declare %an:sequential function s:set-boolean(
287 $pstmnt as xs:anyURI,
288@@ -249,10 +266,12 @@
289 :
290 : @return nothing.
291 :
292- : @error s:SQLI0004 if $pstmnt is not a valid SQLite prepared statement.
293- : @error s:SQLI0005 if $param-num is not a valid position.
294- : @error s:SQLI0006 if $val is not a valid numeric type.
295- : @error s:SQLI9999 if there was an internal error inside SQLite library.
296+ : @error s:INVALID-PREPARED-STATEMENT if $pstmnt is not a valid SQLite prepared
297+ : statement.
298+ : @error s:INVALID-PLACEHOLDER-POSITION if $param-num is not a valid position.
299+ : @error s:INVALID-VALUE if $val is not a valid numeric type.
300+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
301+ : library.
302 :)
303 declare %an:sequential function s:set-numeric(
304 $pstmnt as xs:anyURI,
305@@ -268,9 +287,11 @@
306 :
307 : @return nothing.
308 :
309- : @error s:SQLI0004 if $pstmnt is not a valid SQLite prepared statement.
310- : @error s:SQLI0005 if $param-num is not a valid position.
311- : @error s:SQLI9999 if there was an internal error inside SQLite library.
312+ : @error s:INVALID-PREPARED-STATEMENT if $pstmnt is not a valid SQLite prepared
313+ : statement.
314+ : @error s:INVALID-PLACEHOLDER-POSITION if $param-num is not a valid position.
315+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
316+ : library.
317 :)
318 declare %an:sequential function s:set-string(
319 $pstmnt as xs:anyURI,
320@@ -285,9 +306,11 @@
321 :
322 : @return nothing.
323 :
324- : @error s:SQLI0004 if $pstmnt is not a valid SQLite prepared statement.
325- : @error s:SQLI0005 if $param-num is not a valid position.
326- : @error s:SQLI9999 if there was an internal error inside SQLite library.
327+ : @error s:INVALID-PREPARED-STATEMENT if $pstmnt is not a valid SQLite prepared
328+ : statement.
329+ : @error s:INVALID-PLACEHOLDER-POSITION if $param-num is not a valid position.
330+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
331+ : library.
332 :)
333 declare %an:sequential function s:set-null(
334 $pstmnt as xs:anyURI,
335@@ -300,8 +323,10 @@
336 :
337 : @return nothing.
338 :
339- : @error s:SQLI0004 if $pstmnt is not a valid SQLite prepared statement.
340- : @error s:SQLI9999 if there was an internal error inside SQLite library.
341+ : @error s:INVALID-PREPARED-STATEMENT if $pstmnt is not a valid SQLite prepared
342+ : statement.
343+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
344+ : library.
345 :)
346 declare %an:sequential function s:clear-params(
347 $pstmnt as xs:anyURI ) as empty-sequence() external;
348@@ -313,7 +338,8 @@
349 :
350 : @return nothing.
351 :
352- : @error s:SQLI0004 if $pstmnt is not a valid SQLite prepared statement.
353+ : @error s:INVALID-PREPARED-STATEMENT if $pstmnt is not a valid SQLite prepared
354+ : statement.
355 :)
356 declare %an:sequential function s:close-prepared(
357 $pstmnt as xs:anyURI ) as empty-sequence() external;
358@@ -326,8 +352,10 @@
359 :
360 : @return a sequence of JSON objects representing the query results.
361 :
362- : @error s:SQLI0004 if $pstmnt is not a valid SQLite prepared statement.
363- : @error s:SQLI9999 if there was an internal error inside SQLite library.
364+ : @error s:INVALID-PREPARED-STATEMENT if $pstmnt is not a valid SQLite prepared
365+ : statement.
366+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
367+ : library.
368 :)
369 declare %an:sequential function s:execute-query-prepared(
370 $pstmnt as xs:anyURI ) as object()* external;
371@@ -340,8 +368,10 @@
372 :
373 : @return an integer that represents the amount of rows affected.
374 :
375- : @error s:SQLI0004 if $pstmnt is not a valid SQLite prepared statement.
376- : @error s:SQLI9999 if there was an internal error inside SQLite library.
377+ : @error s:INVALID-PREPARED-STATEMENT if $pstmnt is not a valid SQLite prepared
378+ : statement.
379+ : @error s:INTERNAL-SQLITE-PROBLEM if there was an internal error inside SQLite
380+ : library.
381 :)
382 declare %an:sequential function s:execute-update-prepared(
383 $pstmnt as xs:anyURI ) as xs:integer external;
384
385=== modified file 'src/sqlite_module.xq.src/sqlite_module.cpp'
386--- src/sqlite_module.xq.src/sqlite_module.cpp 2013-06-21 03:41:36 +0000
387+++ src/sqlite_module.xq.src/sqlite_module.cpp 2013-07-30 00:41:26 +0000
388@@ -35,43 +35,66 @@
389
390 namespace zorba { namespace sqlite {
391
392+// Allocating global variables
393+zorba::Item SqliteModule::globalNameKey;
394+zorba::Item SqliteModule::globalDatabaseKey;
395+zorba::Item SqliteModule::globalTableKey;
396+zorba::Item SqliteModule::globalTypeKey;
397+zorba::Item SqliteModule::globalCollationKey;
398+zorba::Item SqliteModule::globalNullableKey;
399+zorba::Item SqliteModule::globalPrimaryKey;
400+zorba::Item SqliteModule::globalAutoincKey;
401+zorba::Item SqliteModule::globalAffectedRowsKey;
402
403 /*******************************************************************************
404 ******************************************************************************/
405- zorba::ExternalFunction*
406- SqliteModule::getExternalFunction(const zorba::String& localName)
407+SqliteModule::SqliteModule()
408+{
409+ globalNameKey = Zorba::getInstance(0)->getItemFactory()->createString("name");
410+ globalDatabaseKey = Zorba::getInstance(0)->getItemFactory()->createString("database");
411+ globalTableKey = Zorba::getInstance(0)->getItemFactory()->createString("table");
412+ globalTypeKey = Zorba::getInstance(0)->getItemFactory()->createString("type");
413+ globalCollationKey = Zorba::getInstance(0)->getItemFactory()->createString("collation");
414+ globalNullableKey = Zorba::getInstance(0)->getItemFactory()->createString("nullable");
415+ globalPrimaryKey = Zorba::getInstance(0)->getItemFactory()->createString("primary key");
416+ globalAutoincKey = Zorba::getInstance(0)->getItemFactory()->createString("autoincrement");
417+ globalAffectedRowsKey = Zorba::getInstance(0)->getItemFactory()->createString("Affected Rows");
418+}
419+
420+zorba::ExternalFunction*
421+SqliteModule::getExternalFunction(const zorba::String& localName)
422+{
423+ FuncMap_t::iterator lIte = theFunctions.find(localName);
424+
425+ ExternalFunction*& lFunc = theFunctions[localName];
426+
427+ if (lIte == theFunctions.end())
428 {
429- FuncMap_t::iterator lIte = theFunctions.find(localName);
430-
431- ExternalFunction*& lFunc = theFunctions[localName];
432-
433- if (lIte == theFunctions.end())
434- {
435- if (localName == "connect")
436- {
437- lFunc = new ConnectFunction(this);
438- }
439- else if (localName == "is-connected")
440- {
441- lFunc = new IsConnectedFunction(this);
442- }
443- else if (localName == "commit")
444- {
445- lFunc = new CommitFunction(this);
446- }
447- else if (localName == "rollback")
448- {
449- lFunc = new RollbackFunction(this);
450- }
451- else if (localName == "execute-query")
452- {
453- lFunc = new ExecuteQueryFunction(this);
454- }
455- else if (localName == "execute-update")
456- {
457- lFunc = new ExecuteUpdateFunction(this);
458- }
459- else if (localName == "metadata")
460+ if (localName == "connect")
461+ {
462+ lFunc = new ConnectFunction(this);
463+ }
464+ else if (localName == "is-connected")
465+ {
466+ lFunc = new IsConnectedFunction(this);
467+ }
468+ else if (localName == "commit")
469+ {
470+ lFunc = new CommitFunction(this);
471+ }
472+ else if (localName == "rollback")
473+ {
474+ lFunc = new RollbackFunction(this);
475+ }
476+ else if (localName == "execute-query")
477+ {
478+ lFunc = new ExecuteQueryFunction(this);
479+ }
480+ else if (localName == "execute-update")
481+ {
482+ lFunc = new ExecuteUpdateFunction(this);
483+ }
484+ else if (localName == "metadata")
485 {
486 lFunc = new MetadataFunction(this);
487 }
488@@ -135,6 +158,25 @@
489 theFunctions.clear();
490 }
491
492+ zorba::Item&
493+ SqliteModule::getGlobalKey(GLOBAL_KEYS g)
494+ {
495+ switch(g)
496+ {
497+ case NAME: return globalNameKey;
498+ case DATABASE: return globalDatabaseKey;
499+ case TABLE: return globalTableKey;
500+ case TYPE: return globalTypeKey;
501+ case COLLATION: return globalCollationKey;
502+ case NULLABLE: return globalNullableKey;
503+ case PRIMARY_KEY: return globalPrimaryKey;
504+ case AUTOINC: return globalAutoincKey;
505+ case AFFECTED_ROWS: return globalAffectedRowsKey;
506+ // Should never touch this case but still ...
507+ default: return globalNameKey;
508+ }
509+ }
510+
511 /***********************
512 * ConnMap *
513 ***********************/
514@@ -324,7 +366,8 @@
515 }
516
517 sqlite3_stmt*
518- SqliteFunction::createPreparedStatement(const zorba::DynamicContext* aDctx, std::string aUUID, std::string aQry){
519+ SqliteFunction::createPreparedStatement(const zorba::DynamicContext* aDctx,
520+ std::string aUUID, std::string aQry){
521 sqlite3 *lDb;
522 sqlite3_stmt *lPstmt;
523 int lRc;
524@@ -334,7 +377,7 @@
525 lDb = lConnMap->getConn(aUUID);
526 if(lDb == NULL){
527 // throw error, ID not recognized
528- throwError("SQLI0002", getErrorMessage("SQLI0002"));
529+ throwError("INVALID-SQLITE-OBJECT", getErrorMessage("INVALID-SQLITE-OBJECT"));
530 }
531
532 lRc = sqlite3_prepare_v2(lDb, aQry.c_str(), aQry.size(), &lPstmt, &lTail);
533@@ -342,10 +385,10 @@
534 sqlite3_finalize(lPstmt);
535 }
536 if(lRc == SQLITE_ERROR) {
537- std::string lErr = getErrorMessage("SQLI0003");
538+ std::string lErr = getErrorMessage("INVALID-SQL-STATEMENT");
539 lErr += "; ";
540 lErr += sqlite3_errmsg(lDb);
541- throwError("SQLI0003", lErr.c_str());
542+ throwError("INVALID-SQL-STATEMENT", lErr.c_str());
543 } else
544 checkForError(lRc, 0, lDb);
545
546@@ -364,11 +407,13 @@
547 // Get the prepared statement and then set the value
548 lPstmt = stmtMap->getStmt(aUUID);
549 if(lPstmt == NULL){
550- throwError("SQLI0004", getErrorMessage("SQLI0004"));
551+ throwError("INVALID-PREPARED-STATEMENT",
552+ getErrorMessage("INVALID-PREPARED-STATEMENT"));
553 }
554 lRc = sqlite3_bind_int(lPstmt, aPos, (aVal==true)?1:0);
555 if(lRc == SQLITE_RANGE)
556- throwError("SQLI0005", getErrorMessage("SQLI0005"));
557+ throwError("INVALID-PLACEHOLDER-POSITION",
558+ getErrorMessage("INVALID-PLACEHOLDER-POSITION"));
559 else
560 checkForError(lRc, 0, sqlite3_db_handle(lPstmt));
561 }
562@@ -386,11 +431,13 @@
563 // Get the prepared statement and then set the value
564 lPstmt = stmtMap->getStmt(aUUID);
565 if(lPstmt == NULL){
566- throwError("SQLI0004", getErrorMessage("SQLI0004"));
567+ throwError("INVALID-PREPARED-STATEMENT",
568+ getErrorMessage("INVALID-PREPARED-STATEMENT"));
569 }
570 lRc = sqlite3_bind_int(lPstmt, aPos, aVal);
571 if(lRc == SQLITE_RANGE)
572- throwError("SQLI0005", getErrorMessage("SQLI0005"));
573+ throwError("INVALID-PLACEHOLDER-POSITION",
574+ getErrorMessage("INVALID-PLACEHOLDER-POSITION"));
575 else
576 checkForError(lRc, 0, sqlite3_db_handle(lPstmt));
577 }
578@@ -408,11 +455,13 @@
579 // Get the prepared statement and then set the value
580 lPstmt = stmtMap->getStmt(aUUID);
581 if(lPstmt == NULL){
582- throwError("SQLI0004", getErrorMessage("SQLI0004"));
583+ throwError("INVALID-PREPARED-STATEMENT",
584+ getErrorMessage("INVALID-PREPARED-STATEMENT"));
585 }
586 lRc = sqlite3_bind_double(lPstmt, aPos, aVal);
587 if(lRc == SQLITE_RANGE)
588- throwError("SQLI0005", getErrorMessage("SQLI0005"));
589+ throwError("INVALID-PLACEHOLDER-POSITION",
590+ getErrorMessage("INVALID-PLACEHOLDER-POSITION"));
591 else
592 checkForError(lRc, 0, sqlite3_db_handle(lPstmt));
593 }
594@@ -430,11 +479,13 @@
595 // Get the prepared statement and then set the value
596 lPstmt = stmtMap->getStmt(aUUID);
597 if(lPstmt == NULL){
598- throwError("SQLI0004", getErrorMessage("SQLI0004"));
599+ throwError("INVALID-PREPARED-STATEMENT",
600+ getErrorMessage("INVALID-PREPARED-STATEMENT"));
601 }
602 lRc = sqlite3_bind_text(lPstmt, aPos, aVal.c_str(), aVal.size(), SQLITE_TRANSIENT);
603 if(lRc == SQLITE_RANGE)
604- throwError("SQLI0005", getErrorMessage("SQLI0005"));
605+ throwError("INVALID-PLACEHOLDER-POSITION",
606+ getErrorMessage("INVALID-PLACEHOLDER-POSITION"));
607 else
608 checkForError(lRc, 0, sqlite3_db_handle(lPstmt));
609 }
610@@ -451,11 +502,13 @@
611 // Get the prepared statement and then set the value
612 lPstmt = stmtMap->getStmt(aUUID);
613 if(lPstmt == NULL){
614- throwError("SQLI0004", getErrorMessage("SQLI0004"));
615+ throwError("INVALID-PREPARED-STATEMENT",
616+ getErrorMessage("INVALID-PREPARED-STATEMENT"));
617 }
618 lRc = sqlite3_bind_null(lPstmt, aPos);
619 if(lRc == SQLITE_RANGE)
620- throwError("SQLI0005", getErrorMessage("SQLI0005"));
621+ throwError("INVALID-PLACEHOLDER-POSITION",
622+ getErrorMessage("INVALID-PLACEHOLDER-POSITION"));
623 else
624 checkForError(lRc, 0, sqlite3_db_handle(lPstmt));
625 }
626@@ -470,7 +523,8 @@
627 // get the prepared statement if exists
628 lPstmt = stmtMap->getStmt(aUUID);
629 if(lPstmt == NULL){
630- throwError("SQLI0004", getErrorMessage("SQLI0004"));
631+ throwError("INVALID-PREPARED-STATEMENT",
632+ getErrorMessage("INVALID-PREPARED-STATEMENT"));
633 }
634 sqlite3_clear_bindings(lPstmt);
635 }
636@@ -502,7 +556,7 @@
637 {
638 if (!aLocalName)
639 {
640- throwError("SQLI9999", sqlite3_errmsg(sql));
641+ throwError("INTERNAL-SQLITE-PROBLEM", sqlite3_errmsg(sql));
642 }
643 else
644 {
645@@ -539,47 +593,47 @@
646
647 const char *
648 SqliteFunction::getErrorMessage(std::string error){
649- if(error == "SQLI0001")
650+ if(error == "CANT-OPEN-DB")
651 {
652 return "Database file does not exist or it is not possible to open it";
653 }
654- else if(error == "SQLI0002")
655+ else if(error == "INVALID-SQLITE-OBJECT")
656 {
657 return "Connection ID passed is not valid";
658 }
659- else if(error == "SQLI0003")
660+ else if(error == "INVALID-SQL-STATEMENT")
661 {
662 return "Statement passed is not a valid SQL statement";
663 }
664- else if(error == "SQLI0004")
665+ else if(error == "INVALID-PREPARED-STATEMENT")
666 {
667 return "Prepared statement passed is not valid";
668 }
669- else if(error == "SQLI0005")
670+ else if(error == "INVALID-PLACEHOLDER-POSITION")
671 {
672 return "Parameter position passed is not valid";
673 }
674- else if(error == "SQLI0006")
675+ else if(error == "INVALID-VALUE")
676 {
677 return "Parameter passed is not a valid number";
678 }
679- else if(error == "SQLI0007")
680+ else if(error == "UNKNOWN-OPTION")
681 {
682 return "Parameter passed is not a valid value";
683 }
684 #ifndef SQLITE_WITH_FILE_ACCESS
685- else if(error == "SQLI0008")
686+ else if(error == "COMPILED-WITHOUT-DISK-ACCESS")
687 {
688 return "Only in-memory databases are allowed (Module built without filesystem access)";
689 }
690 #endif /* not SQLITE_WITH_FILE_ACCESS */
691 #ifndef ZORBA_SQLITE_HAVE_METADATA
692- else if(error == "SQLI0009")
693+ else if(error == "UNAVAILABLE-METADATA")
694 {
695 return "Metadata not found (SQLite built without SQLITE_ENABLE_COLUMN_METADATA)";
696 }
697 #endif /* not ZORBA_SQLITE_HAVE_METADATA */
698- else if(error == "SQLI9999")
699+ else if(error == "INTERNAL-SQLITE-PROBLEM")
700 {
701 return "Internal error ocurred";
702 }
703@@ -632,7 +686,9 @@
704 } else
705 // Not sure if I should stop here in case that any option
706 // are not in the list
707- SqliteFunction::throwError("SQLI0007", (std::string(SqliteFunction::getErrorMessage("SQLI0007")) + " - " + lItemJSONKey.getStringValue().str()).c_str());
708+ SqliteFunction::throwError("UNKNOWN-OPTION",
709+ (std::string(SqliteFunction::getErrorMessage("UNKNOWN-OPTION")) + " - " +
710+ lItemJSONKey.getStringValue().str()).c_str());
711 }
712 lIterKeys->close();
713 }
714@@ -704,10 +760,13 @@
715 * JSONItemSequence::JSONIterator *
716 ******************************************************************************/
717 void JSONItemSequence::JSONIterator::open(){
718+ zorba::Item lColumnName;
719+ char* lColumnNameChar;
720 // Get data and create the column names
721 if(theStmt != NULL){
722 theRc = sqlite3_step(theStmt);
723- SqliteFunction::checkForError((theRc==SQLITE_ROW || theRc==SQLITE_DONE)?0:-1, 0, sqlite3_db_handle(theStmt));
724+ SqliteFunction::checkForError((theRc==SQLITE_ROW || theRc==SQLITE_DONE)?0:-1, 0,
725+ sqlite3_db_handle(theStmt));
726 if(theRc == SQLITE_DONE)
727 isUpdateResult = true;
728 theFactory = Zorba::getInstance(0)->getItemFactory();
729@@ -715,14 +774,16 @@
730 theColumnCount = sqlite3_column_count(theStmt);
731 if(theColumnCount > 0)
732 {
733- theColumnNames = new char*[theColumnCount];
734 for(int i=0; i<theColumnCount; i++)
735 {
736 const char* lpChar = sqlite3_column_name(theStmt, i);
737 int lLen = strlen(lpChar);
738- theColumnNames[i] = new char[lLen+1];
739- memcpy(theColumnNames[i], lpChar, lLen);
740- theColumnNames[i][lLen] = '\0';
741+ lColumnNameChar = new char[lLen+1];
742+ memcpy(lColumnNameChar, lpChar, lLen);
743+ lColumnNameChar[lLen] = '\0';
744+ lColumnName = theFactory->createString(lColumnNameChar);
745+ theColumnNamesZString.push_back(lColumnName);
746+ delete lColumnNameChar;
747 }
748 }
749 }
750@@ -730,7 +791,6 @@
751
752 bool JSONItemSequence::JSONIterator::next(zorba::Item& aItem){
753 int aType, aSize;
754- zorba::Item aKey;
755 zorba::Item aValue;
756 std::vector<std::pair<zorba::Item, zorba::Item> > elements;
757 const char *aBlobPtr;
758@@ -739,7 +799,6 @@
759 // get the resulting data from the statement
760 // in a key = value fashion
761 for(int i=0; i<theColumnCount; i++){
762- aKey = theFactory->createString(std::string((const char *)theColumnNames[i]));
763 aType = sqlite3_column_type(theStmt, i);
764 switch(aType){
765 case SQLITE_NULL:
766@@ -762,7 +821,7 @@
767 zorba::String(str)
768 );
769 }
770- elements.push_back(std::pair<zorba::Item, zorba::Item>(aKey, aValue));
771+ elements.push_back(std::pair<zorba::Item, zorba::Item>(theColumnNamesZString.at(i), aValue));
772 }
773 aItem = theFactory->createJSONObject(elements);
774 elements.clear();
775@@ -771,9 +830,8 @@
776 return true;
777 } else if(isUpdateResult && theRc == SQLITE_DONE){
778 // we have a prepared statement that represents a UPDATE and it's already executed
779- aKey = theFactory->createString("Affected Rows");
780 aValue = theFactory->createInt(sqlite3_changes(sqlite3_db_handle(theStmt)));
781- elements.push_back(std::pair<zorba::Item, zorba::Item>(aKey, aValue));
782+ elements.push_back(std::pair<zorba::Item, zorba::Item>(SqliteModule::getGlobalKey(SqliteModule::AFFECTED_ROWS), aValue));
783 aItem = theFactory->createJSONObject(elements);
784 elements.clear();
785 // be sure it won't be back in here
786@@ -787,11 +845,9 @@
787 void JSONItemSequence::JSONIterator::close(){
788 // Set the Rc to "no more data" and clear the variables
789 theRc = SQLITE_ERROR;
790- if((theColumnCount > 0) && theColumnNames)
791+ if(theColumnCount > 0)
792 {
793- for(int i=0; i<theColumnCount; i++)
794- delete[] theColumnNames[i];
795- delete[] theColumnNames;
796+ theColumnNamesZString.clear();
797 }
798 theColumnCount = 0;
799 if(theStmt != NULL)
800@@ -806,7 +862,8 @@
801 // Get data and create the column names
802 if(theStmt != NULL){
803 theRc = sqlite3_step(theStmt);
804- SqliteFunction::checkForError((theRc==SQLITE_ROW || theRc==SQLITE_DONE)?0:-1, 0, sqlite3_db_handle(theStmt));
805+ SqliteFunction::checkForError((theRc==SQLITE_ROW || theRc==SQLITE_DONE)?0:-1, 0,
806+ sqlite3_db_handle(theStmt));
807 theFactory = Zorba::getInstance(0)->getItemFactory();
808
809 theColumnCount = sqlite3_column_count(theStmt);
810@@ -821,7 +878,7 @@
811 }
812
813 bool JSONMetadataItemSequence::JSONMetadataIterator::next(zorba::Item& aItem){
814- zorba::Item aKey;
815+ //zorba::Item aKey;
816 zorba::Item aValue;
817 std::vector<std::pair<zorba::Item, zorba::Item> > elements;
818 sqlite3 *lDbHandle;
819@@ -850,30 +907,22 @@
820 &lAutoinc);
821 if(lRc != 0)
822 SqliteFunction::throwError(0, sqlite3_errmsg(lDbHandle));
823- aKey = theFactory->createString("name");
824 aValue = theFactory->createString(lOriginName);
825- elements.push_back(std::pair<zorba::Item, zorba::Item>(aKey, aValue));
826- aKey = theFactory->createString("database");
827+ elements.push_back(std::pair<zorba::Item, zorba::Item>(SqliteModule::getGlobalKey(SqliteModule::NAME), aValue));
828 aValue = theFactory->createString(lDbName);
829- elements.push_back(std::pair<zorba::Item, zorba::Item>(aKey, aValue));
830- aKey = theFactory->createString("table");
831+ elements.push_back(std::pair<zorba::Item, zorba::Item>(SqliteModule::getGlobalKey(SqliteModule::DATABASE), aValue));
832 aValue = theFactory->createString(lTableName);
833- elements.push_back(std::pair<zorba::Item, zorba::Item>(aKey, aValue));
834- aKey = theFactory->createString("type");
835+ elements.push_back(std::pair<zorba::Item, zorba::Item>(SqliteModule::getGlobalKey(SqliteModule::TABLE), aValue));
836 aValue = theFactory->createString(lDataType);
837- elements.push_back(std::pair<zorba::Item, zorba::Item>(aKey, aValue));
838- aKey = theFactory->createString("collation");
839+ elements.push_back(std::pair<zorba::Item, zorba::Item>(SqliteModule::getGlobalKey(SqliteModule::TYPE), aValue));
840 aValue = theFactory->createString(lCollSequence);
841- elements.push_back(std::pair<zorba::Item, zorba::Item>(aKey, aValue));
842- aKey = theFactory->createString("nullable");
843+ elements.push_back(std::pair<zorba::Item, zorba::Item>(SqliteModule::getGlobalKey(SqliteModule::COLLATION), aValue));
844 aValue = theFactory->createBoolean((lNotNull==0)?false:true);
845- elements.push_back(std::pair<zorba::Item, zorba::Item>(aKey, aValue));
846- aKey = theFactory->createString("primary key");
847+ elements.push_back(std::pair<zorba::Item, zorba::Item>(SqliteModule::getGlobalKey(SqliteModule::NULLABLE), aValue));
848 aValue = theFactory->createBoolean((lPrimaryKey==0)?false:true);
849- elements.push_back(std::pair<zorba::Item, zorba::Item>(aKey, aValue));
850- aKey = theFactory->createString("autoincrement");
851+ elements.push_back(std::pair<zorba::Item, zorba::Item>(SqliteModule::getGlobalKey(SqliteModule::PRIMARY_KEY), aValue));
852 aValue = theFactory->createBoolean((lAutoinc==0)?false:true);
853- elements.push_back(std::pair<zorba::Item, zorba::Item>(aKey, aValue));
854+ elements.push_back(std::pair<zorba::Item, zorba::Item>(SqliteModule::getGlobalKey(SqliteModule::AUTOINC), aValue));
855 aItem = theFactory->createJSONObject(elements);
856 elements.clear();
857 // Get more data if available
858@@ -927,7 +976,8 @@
859
860 #ifndef SQLITE_WITH_FILE_ACCESS
861 if (lDbName != ":memory:") {
862- throwError("SQLI0008", getErrorMessage("SQLI0008"));
863+ throwError("COMPILED-WITHOUT-DISK-ACCESS",
864+ getErrorMessage("COMPILED-WITHOUT-DISK-ACCESS"));
865 }
866 #endif /* not SQLITE_WITH_FILE_ACCESS */
867 lRc = sqlite3_open_v2(lDbName.c_str(), &lSqldb, lOptions.getOptionsAsInt(), NULL);
868@@ -935,7 +985,7 @@
869 lStrUUID = createUUID();
870 lConnMap->storeConn(lStrUUID, lSqldb);
871 if(lRc == SQLITE_CANTOPEN)
872- throwError("SQLI0001", getErrorMessage("SQLI0001"));
873+ throwError("CANT-OPEN-DB", getErrorMessage("CANT-OPEN-DB"));
874 else
875 checkForError(lRc, 0, lSqldb);
876
877@@ -981,7 +1031,7 @@
878
879 lDb = lConnMap->getConn(lItemUUID.getStringValue().str());
880 if(lDb == NULL)
881- throwError("SQLI0002", getErrorMessage("SQLI0002"));
882+ throwError("INVALID-SQLITE-OBJECT", getErrorMessage("INVALID-SQLITE-OBJECT"));
883
884 return ItemSequence_t(new SingletonItemSequence(lItemUUID));
885 }
886@@ -1000,7 +1050,7 @@
887
888 lDb = lConnMap->getConn(lItemUUID.getStringValue().str());
889 if(lDb == NULL)
890- throwError("SQLI0002", getErrorMessage("SQLI0002"));
891+ throwError("INVALID-SQLITE-OBJECT", getErrorMessage("INVALID-SQLITE-OBJECT"));
892
893 return ItemSequence_t(new SingletonItemSequence(lItemUUID));
894 }
895@@ -1091,7 +1141,8 @@
896 lPstmt = lStmtMap->getStmt(lItemPstmt.getStringValue().str());
897 if(lPstmt == NULL){
898 // No valid prepared statement id passed
899- throwError("SQLI0004", getErrorMessage("SQLI0004"));
900+ throwError("INVALID-PREPARED-STATEMENT",
901+ getErrorMessage("INVALID-PREPARED-STATEMENT"));
902 }
903
904 // So now create a JSONMetadataItemSequence and let it
905@@ -1111,7 +1162,7 @@
906
907 return ItemSequence_t(new SingletonItemSequence(lJSONRes));
908 #else
909- throwError("SQLI0009", getErrorMessage("SQLI0009"));
910+ throwError("UNAVAILABLE-METADATA", getErrorMessage("UNAVAILABLE-METADATA"));
911 #endif
912 }
913
914@@ -1156,27 +1207,33 @@
915 lPos = strToInt(lItemPos.getStringValue().str());
916 switch(lItem.getTypeCode()){
917 case store::XS_BOOLEAN:
918- setValueToStatement(aDctx, lItemUUID.getStringValue().str(), lPos, lItem.getBooleanValue());
919+ setValueToStatement(aDctx, lItemUUID.getStringValue().str(),
920+ lPos, lItem.getBooleanValue());
921 break;
922 case store::XS_BYTE:
923 case store::XS_INT:
924- setValueToStatement(aDctx, lItemUUID.getStringValue().str(), lPos, lItem.getIntValue());
925+ setValueToStatement(aDctx, lItemUUID.getStringValue().str(),
926+ lPos, lItem.getIntValue());
927 break;
928 case store::XS_INTEGER:
929- setValueToStatement(aDctx, lItemUUID.getStringValue().str(), lPos, strToInt(lItem.getStringValue().str()));
930+ setValueToStatement(aDctx, lItemUUID.getStringValue().str(),
931+ lPos, strToInt(lItem.getStringValue().str()));
932 break;
933 case store::XS_FLOAT:
934 case store::XS_DOUBLE:
935- setValueToStatement(aDctx, lItemUUID.getStringValue().str(), lPos, lItem.getDoubleValue());
936+ setValueToStatement(aDctx, lItemUUID.getStringValue().str(),
937+ lPos, lItem.getDoubleValue());
938 break;
939 case store::XS_DECIMAL:
940- setValueToStatement(aDctx, lItemUUID.getStringValue().str(), lPos, strToDouble(lItem.getStringValue().str()));
941+ setValueToStatement(aDctx, lItemUUID.getStringValue().str(),
942+ lPos, strToDouble(lItem.getStringValue().str()));
943 break;
944 case store::XS_STRING:
945- setValueToStatement(aDctx, lItemUUID.getStringValue().str(), lPos, lItem.getStringValue().str());
946+ setValueToStatement(aDctx, lItemUUID.getStringValue().str(),
947+ lPos, lItem.getStringValue().str());
948 break;
949 default:
950- throwError("SQLI0007", getErrorMessage("SQLI0007"));
951+ throwError("INVALID-VALUE", getErrorMessage("INVALID-VALUE"));
952 }
953 return ItemSequence_t(new EmptySequence());
954 }
955@@ -1193,7 +1250,8 @@
956 Item lItemPos = getOneItem(aArgs, 1);
957 Item lItemBool = getOneItem(aArgs, 2);
958
959- setValueToStatement(aDctx, lItemUUID.getStringValue().str(), strToInt(lItemPos.getStringValue().str()), lItemBool.getBooleanValue());
960+ setValueToStatement(aDctx, lItemUUID.getStringValue().str(),
961+ strToInt(lItemPos.getStringValue().str()), lItemBool.getBooleanValue());
962 return ItemSequence_t(new EmptySequence());
963 }
964
965@@ -1213,20 +1271,24 @@
966 switch(lItemNumeric.getTypeCode()){
967 case store::XS_BYTE:
968 case store::XS_INT:
969- setValueToStatement(aDctx, lItemUUID.getStringValue().str(), lPos, lItemNumeric.getIntValue());
970+ setValueToStatement(aDctx, lItemUUID.getStringValue().str(),
971+ lPos, lItemNumeric.getIntValue());
972 break;
973 case store::XS_INTEGER:
974- setValueToStatement(aDctx, lItemUUID.getStringValue().str(), lPos, strToInt(lItemNumeric.getStringValue().str()));
975+ setValueToStatement(aDctx, lItemUUID.getStringValue().str(),
976+ lPos, strToInt(lItemNumeric.getStringValue().str()));
977 break;
978 case store::XS_FLOAT:
979 case store::XS_DOUBLE:
980- setValueToStatement(aDctx, lItemUUID.getStringValue().str(), lPos, lItemNumeric.getDoubleValue());
981+ setValueToStatement(aDctx, lItemUUID.getStringValue().str(),
982+ lPos, lItemNumeric.getDoubleValue());
983 break;
984 case store::XS_DECIMAL:
985- setValueToStatement(aDctx, lItemUUID.getStringValue().str(), lPos, strToDouble(lItemNumeric.getStringValue().str()));
986+ setValueToStatement(aDctx, lItemUUID.getStringValue().str(),
987+ lPos, strToDouble(lItemNumeric.getStringValue().str()));
988 break;
989 default:
990- throwError("SQLI0006", getErrorMessage("SQLI0006"));
991+ throwError("INVALID-VALUE", getErrorMessage("INVALID-VALUE"));
992 }
993 return ItemSequence_t(new EmptySequence());
994 }
995@@ -1243,7 +1305,8 @@
996 Item lItemPos = getOneItem(aArgs, 1);
997 Item lItemString = getOneItem(aArgs, 2);
998
999- setValueToStatement(aDctx, lItemUUID.getStringValue().str(), strToInt(lItemPos.getStringValue().str()), lItemString.getStringValue().str());
1000+ setValueToStatement(aDctx, lItemUUID.getStringValue().str(),
1001+ strToInt(lItemPos.getStringValue().str()), lItemString.getStringValue().str());
1002 return ItemSequence_t(new EmptySequence());
1003 }
1004
1005@@ -1258,7 +1321,8 @@
1006 Item lItemUUID = getOneItem(aArgs, 0);
1007 Item lItemPos = getOneItem(aArgs, 1);
1008
1009- setValueToStatement(aDctx, lItemUUID.getStringValue().str(), strToInt(lItemPos.getStringValue().str()));
1010+ setValueToStatement(aDctx, lItemUUID.getStringValue().str(),
1011+ strToInt(lItemPos.getStringValue().str()));
1012 return ItemSequence_t(new EmptySequence());
1013 }
1014
1015@@ -1292,7 +1356,8 @@
1016 stmtMap = getStatementMap(aDctx);
1017 lPstmt = stmtMap->getStmt(lItemUUID.getStringValue().str());
1018 if(lPstmt == NULL)
1019- throwError("SQLI0004", getErrorMessage("SQLI0004"));
1020+ throwError("INVALID-PREPARED-STATEMENT",
1021+ getErrorMessage("INVALID-PREPARED-STATEMENT"));
1022
1023 // Once we got the prepared statement just get rid of it
1024 stmtMap->deleteStmt(lItemUUID.getStringValue().str());
1025@@ -1314,7 +1379,8 @@
1026 // Get the prepared statement
1027 lPstmt = stmtMap->getStmt(lItemUUID.getStringValue().str());
1028 if(lPstmt == NULL)
1029- throwError("SQLI0004", getErrorMessage("SQLI0004"));
1030+ throwError("INVALID-PREPARED-STATEMENT",
1031+ getErrorMessage("INVALID-PREPARED-STATEMENT"));
1032
1033 // And let the JSONItemSequence execute it
1034 std::auto_ptr<JSONItemSequence> lSeq(new JSONItemSequence(lPstmt));
1035@@ -1337,7 +1403,8 @@
1036 // Get the prepared statement
1037 lPstmt = stmtMap->getStmt(lItemUUID.getStringValue().str());
1038 if(lPstmt == NULL)
1039- throwError("SQLI0004", getErrorMessage("SQLI0004"));
1040+ throwError("INVALID-PREPARED-STATEMENT",
1041+ getErrorMessage("INVALID-PREPARED-STATEMENT"));
1042
1043 // And let the JSONItemSequence execute it
1044 std::auto_ptr<JSONItemSequence> lSeq(new JSONItemSequence(lPstmt));
1045
1046=== modified file 'src/sqlite_module.xq.src/sqlite_module.h'
1047--- src/sqlite_module.xq.src/sqlite_module.h 2013-02-18 22:15:44 +0000
1048+++ src/sqlite_module.xq.src/sqlite_module.h 2013-07-30 00:41:26 +0000
1049@@ -82,8 +82,22 @@
1050 typedef std::map<String, ExternalFunction*, ltstr> FuncMap_t;
1051 FuncMap_t theFunctions;
1052
1053+ static zorba::Item globalNameKey;
1054+ static zorba::Item globalDatabaseKey;
1055+ static zorba::Item globalTableKey;
1056+ static zorba::Item globalTypeKey;
1057+ static zorba::Item globalCollationKey;
1058+ static zorba::Item globalNullableKey;
1059+ static zorba::Item globalPrimaryKey;
1060+ static zorba::Item globalAutoincKey;
1061+ static zorba::Item globalAffectedRowsKey;
1062+
1063 public:
1064
1065+ enum GLOBAL_KEYS { NAME, DATABASE, TABLE, TYPE, COLLATION, NULLABLE, PRIMARY_KEY, AUTOINC, AFFECTED_ROWS };
1066+
1067+ SqliteModule();
1068+
1069 virtual ~SqliteModule();
1070
1071 virtual zorba::String
1072@@ -101,7 +115,10 @@
1073 }
1074
1075 static zorba::String
1076- getModuleURI() { return "http://www.zorba-xquery.com/modules/sqlite"; }
1077+ getModuleURI() { return "http://zorba.io/modules/sqlite"; }
1078+
1079+ static zorba::Item&
1080+ getGlobalKey(GLOBAL_KEYS g);
1081
1082 };
1083
1084@@ -115,7 +132,7 @@
1085 {
1086 protected:
1087 sqlite3_stmt* theStmt;
1088- char** theColumnNames;
1089+ std::vector<zorba::Item> theColumnNamesZString;
1090 int theColumnCount;
1091 int theRc;
1092 bool isUpdateResult;
1093@@ -123,7 +140,7 @@
1094
1095 public:
1096 JSONIterator(sqlite3_stmt* aPrepStmt):
1097- theStmt(aPrepStmt),theColumnNames(NULL),theColumnCount(0),
1098+ theStmt(aPrepStmt),
1099 theRc(0),isUpdateResult(false) {}
1100
1101 virtual ~JSONIterator() {
1102
1103=== modified file 'test/Queries/test0.xq'
1104--- test/Queries/test0.xq 2013-01-09 15:07:19 +0000
1105+++ test/Queries/test0.xq 2013-07-30 00:41:26 +0000
1106@@ -1,4 +1,4 @@
1107-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1108+import module namespace s = "http://zorba.io/modules/sqlite";
1109 import module namespace f = "http://expath.org/ns/file";
1110
1111 let $path := f:path-to-native(resolve-uri("./"))
1112
1113=== modified file 'test/Queries/test1.xq'
1114--- test/Queries/test1.xq 2013-01-09 15:07:19 +0000
1115+++ test/Queries/test1.xq 2013-07-30 00:41:26 +0000
1116@@ -1,4 +1,4 @@
1117-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1118+import module namespace s = "http://zorba.io/modules/sqlite";
1119
1120 let $db := s:connect("")
1121
1122
1123=== modified file 'test/Queries/test10.xq'
1124--- test/Queries/test10.xq 2013-03-21 01:33:18 +0000
1125+++ test/Queries/test10.xq 2013-07-30 00:41:26 +0000
1126@@ -1,4 +1,4 @@
1127-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1128+import module namespace s = "http://zorba.io/modules/sqlite";
1129
1130 let $db := s:connect("", { "open-read-only" : false(), "open-create" : false() })
1131
1132
1133=== modified file 'test/Queries/test11.spec'
1134--- test/Queries/test11.spec 2012-12-06 23:47:48 +0000
1135+++ test/Queries/test11.spec 2013-07-30 00:41:26 +0000
1136@@ -1,1 +1,1 @@
1137-Error: http://www.zorba-xquery.com/modules/sqlite:SQLI0003
1138+Error: http://zorba.io/modules/sqlite:INVALID-SQL-STATEMENT
1139
1140=== modified file 'test/Queries/test11.xq'
1141--- test/Queries/test11.xq 2013-01-09 15:07:19 +0000
1142+++ test/Queries/test11.xq 2013-07-30 00:41:26 +0000
1143@@ -1,4 +1,4 @@
1144-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1145+import module namespace s = "http://zorba.io/modules/sqlite";
1146
1147 let $db := s:connect("")
1148
1149
1150=== modified file 'test/Queries/test12.spec'
1151--- test/Queries/test12.spec 2012-12-06 23:47:48 +0000
1152+++ test/Queries/test12.spec 2013-07-30 00:41:26 +0000
1153@@ -1,1 +1,1 @@
1154-Error: http://www.zorba-xquery.com/modules/sqlite:SQLI0001
1155+Error: http://zorba.io/modules/sqlite:CANT-OPEN-DB
1156
1157=== modified file 'test/Queries/test12.xq'
1158--- test/Queries/test12.xq 2013-03-21 01:33:18 +0000
1159+++ test/Queries/test12.xq 2013-07-30 00:41:26 +0000
1160@@ -1,4 +1,4 @@
1161-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1162+import module namespace s = "http://zorba.io/modules/sqlite";
1163
1164 let $db := s:connect("non-existent-file.db", {"open-read-only" : false(), "open-create" : false()})
1165
1166
1167=== modified file 'test/Queries/test13.spec'
1168--- test/Queries/test13.spec 2012-12-06 23:47:48 +0000
1169+++ test/Queries/test13.spec 2013-07-30 00:41:26 +0000
1170@@ -1,1 +1,1 @@
1171-Error: http://www.zorba-xquery.com/modules/sqlite:SQLI0002
1172+Error: http://zorba.io/modules/sqlite:INVALID-SQLITE-OBJECT
1173
1174=== modified file 'test/Queries/test13.xq'
1175--- test/Queries/test13.xq 2013-01-09 15:07:19 +0000
1176+++ test/Queries/test13.xq 2013-07-30 00:41:26 +0000
1177@@ -1,4 +1,4 @@
1178-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1179+import module namespace s = "http://zorba.io/modules/sqlite";
1180
1181 let $db := s:connect("")
1182
1183
1184=== modified file 'test/Queries/test14.spec'
1185--- test/Queries/test14.spec 2012-12-06 23:47:48 +0000
1186+++ test/Queries/test14.spec 2013-07-30 00:41:26 +0000
1187@@ -1,1 +1,1 @@
1188-Error: http://www.zorba-xquery.com/modules/sqlite:SQLI0004
1189+Error: http://zorba.io/modules/sqlite:INVALID-PREPARED-STATEMENT
1190
1191=== modified file 'test/Queries/test14.xq'
1192--- test/Queries/test14.xq 2013-01-09 15:07:19 +0000
1193+++ test/Queries/test14.xq 2013-07-30 00:41:26 +0000
1194@@ -1,4 +1,4 @@
1195-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1196+import module namespace s = "http://zorba.io/modules/sqlite";
1197
1198 let $db := s:connect("")
1199
1200
1201=== modified file 'test/Queries/test15.spec'
1202--- test/Queries/test15.spec 2012-12-06 23:47:48 +0000
1203+++ test/Queries/test15.spec 2013-07-30 00:41:26 +0000
1204@@ -1,1 +1,1 @@
1205-Error: http://www.zorba-xquery.com/modules/sqlite:SQLI0005
1206+Error: http://zorba.io/modules/sqlite:INVALID-PLACEHOLDER-POSITION
1207
1208=== modified file 'test/Queries/test15.xq'
1209--- test/Queries/test15.xq 2013-01-09 15:07:19 +0000
1210+++ test/Queries/test15.xq 2013-07-30 00:41:26 +0000
1211@@ -1,4 +1,4 @@
1212-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1213+import module namespace s = "http://zorba.io/modules/sqlite";
1214
1215 let $db := s:connect("")
1216
1217
1218=== modified file 'test/Queries/test16.spec'
1219--- test/Queries/test16.spec 2012-12-06 23:47:48 +0000
1220+++ test/Queries/test16.spec 2013-07-30 00:41:26 +0000
1221@@ -1,1 +1,1 @@
1222-Error: http://www.zorba-xquery.com/modules/sqlite:SQLI0006
1223+Error: http://zorba.io/modules/sqlite:INVALID-VALUE
1224
1225=== modified file 'test/Queries/test16.xq'
1226--- test/Queries/test16.xq 2013-01-09 15:07:19 +0000
1227+++ test/Queries/test16.xq 2013-07-30 00:41:26 +0000
1228@@ -1,4 +1,4 @@
1229-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1230+import module namespace s = "http://zorba.io/modules/sqlite";
1231
1232 let $db := s:connect("")
1233
1234
1235=== modified file 'test/Queries/test17.spec'
1236--- test/Queries/test17.spec 2012-12-06 23:47:48 +0000
1237+++ test/Queries/test17.spec 2013-07-30 00:41:26 +0000
1238@@ -1,1 +1,1 @@
1239-Error: http://www.zorba-xquery.com/modules/sqlite:SQLI0007
1240+Error: http://zorba.io/modules/sqlite:UNKNOWN-OPTION
1241
1242=== modified file 'test/Queries/test17.xq'
1243--- test/Queries/test17.xq 2013-03-21 01:33:18 +0000
1244+++ test/Queries/test17.xq 2013-07-30 00:41:26 +0000
1245@@ -1,4 +1,4 @@
1246-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1247+import module namespace s = "http://zorba.io/modules/sqlite";
1248
1249 let $db := s:connect("non-existent-file.db", {"non-existent-option" : true()})
1250
1251
1252=== modified file 'test/Queries/test18.xq'
1253--- test/Queries/test18.xq 2013-01-08 23:59:00 +0000
1254+++ test/Queries/test18.xq 2013-07-30 00:41:26 +0000
1255@@ -1,4 +1,4 @@
1256-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1257+import module namespace s = "http://zorba.io/modules/sqlite";
1258
1259 let $db := s:connect("")
1260
1261
1262=== modified file 'test/Queries/test2.xq'
1263--- test/Queries/test2.xq 2013-01-09 15:07:19 +0000
1264+++ test/Queries/test2.xq 2013-07-30 00:41:26 +0000
1265@@ -1,4 +1,4 @@
1266-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1267+import module namespace s = "http://zorba.io/modules/sqlite";
1268 import module namespace f = "http://expath.org/ns/file";
1269
1270 let $path := f:path-to-native(resolve-uri("./"))
1271
1272=== modified file 'test/Queries/test3.spec'
1273--- test/Queries/test3.spec 2013-01-25 23:29:51 +0000
1274+++ test/Queries/test3.spec 2013-07-30 00:41:26 +0000
1275@@ -1,1 +1,1 @@
1276-Error: http://www.zorba-xquery.com/modules/sqlite:SQLI0009
1277+Error: http://zorba.io/modules/sqlite:UNAVAILABLE-METADATA
1278
1279=== modified file 'test/Queries/test3.xq'
1280--- test/Queries/test3.xq 2013-01-09 15:07:19 +0000
1281+++ test/Queries/test3.xq 2013-07-30 00:41:26 +0000
1282@@ -1,4 +1,4 @@
1283-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1284+import module namespace s = "http://zorba.io/modules/sqlite";
1285 import module namespace f = "http://expath.org/ns/file";
1286
1287 let $path := f:path-to-native(resolve-uri("./"))
1288
1289=== modified file 'test/Queries/test4.spec'
1290--- test/Queries/test4.spec 2013-01-25 23:29:51 +0000
1291+++ test/Queries/test4.spec 2013-07-30 00:41:26 +0000
1292@@ -1,1 +1,1 @@
1293-Error: http://www.zorba-xquery.com/modules/sqlite:SQLI0009
1294+Error: http://zorba.io/modules/sqlite:UNAVAILABLE-METADATA
1295
1296=== modified file 'test/Queries/test4.xq'
1297--- test/Queries/test4.xq 2013-01-09 15:07:19 +0000
1298+++ test/Queries/test4.xq 2013-07-30 00:41:26 +0000
1299@@ -1,4 +1,4 @@
1300-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1301+import module namespace s = "http://zorba.io/modules/sqlite";
1302 import module namespace f = "http://expath.org/ns/file";
1303
1304 let $path := f:path-to-native(resolve-uri("./"))
1305
1306=== modified file 'test/Queries/test5.spec'
1307--- test/Queries/test5.spec 2013-01-25 23:29:51 +0000
1308+++ test/Queries/test5.spec 2013-07-30 00:41:26 +0000
1309@@ -1,1 +1,1 @@
1310-Error: http://www.zorba-xquery.com/modules/sqlite:SQLI0009
1311+Error: http://zorba.io/modules/sqlite:UNAVAILABLE-METADATA
1312
1313=== modified file 'test/Queries/test5.xq'
1314--- test/Queries/test5.xq 2013-01-09 15:07:19 +0000
1315+++ test/Queries/test5.xq 2013-07-30 00:41:26 +0000
1316@@ -1,4 +1,4 @@
1317-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1318+import module namespace s = "http://zorba.io/modules/sqlite";
1319 import module namespace f = "http://expath.org/ns/file";
1320
1321 let $path := f:path-to-native(resolve-uri("./"))
1322
1323=== modified file 'test/Queries/test6.xq'
1324--- test/Queries/test6.xq 2013-01-09 15:07:19 +0000
1325+++ test/Queries/test6.xq 2013-07-30 00:41:26 +0000
1326@@ -1,4 +1,4 @@
1327-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1328+import module namespace s = "http://zorba.io/modules/sqlite";
1329
1330 let $db := s:connect("small2.db")
1331
1332
1333=== modified file 'test/Queries/test7.xq'
1334--- test/Queries/test7.xq 2012-12-19 21:58:28 +0000
1335+++ test/Queries/test7.xq 2013-07-30 00:41:26 +0000
1336@@ -1,4 +1,4 @@
1337-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1338+import module namespace s = "http://zorba.io/modules/sqlite";
1339 import module namespace f = "http://expath.org/ns/file";
1340
1341 let $path := f:path-to-native(resolve-uri("./"))
1342@@ -11,4 +11,4 @@
1343 let $name := $e("name")
1344 let $calories := $e("calories")
1345 return <food><id>{$id}</id><name>{$name}</name><calories>{$calories}</calories></food>
1346-}
1347\ No newline at end of file
1348+}
1349
1350=== modified file 'test/Queries/test8.xq'
1351--- test/Queries/test8.xq 2013-01-09 15:07:19 +0000
1352+++ test/Queries/test8.xq 2013-07-30 00:41:26 +0000
1353@@ -1,4 +1,4 @@
1354-import module namespace s = "http://www.zorba-xquery.com/modules/sqlite";
1355+import module namespace s = "http://zorba.io/modules/sqlite";
1356
1357 let $db := s:connect("")
1358
1359
1360=== modified file 'test/Queries/test9.xq'
1361--- test/Queries/test9.xq 2013-01-08 06:01:04 +0000
1362+++ test/Queries/test9.xq 2013-07-30 00:41:26 +0000
1363@@ -1,5 +1,5 @@
1364 import module namespace s =
1365- "http://www.zorba-xquery.com/modules/sqlite";
1366+ "http://zorba.io/modules/sqlite";
1367
1368 let $xml :=
1369 <root>

Subscribers

People subscribed via source and target branches

to all changes: