1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
diff -ru javasqlite-20080130/native/sqlite_jni.c javasqlite-20080130+iPhone/native/sqlite_jni.c
--- javasqlite-20080130/native/sqlite_jni.c 2008-01-29 09:23:25.000000000 +0000
+++ javasqlite-20080130+iPhone/native/sqlite_jni.c 2008-03-10 23:15:41.000000000 +0000
@@ -3360,6 +3360,8 @@
jsize len16;
const jchar *sql16, *tail = 0;
int ret;
+ int i;
+ jchar *sql2;
if (!h) {
throwclosed(env);
@@ -3385,11 +3387,15 @@
}
h->env = env;
sql16 = (*env)->GetStringChars(env, sql, 0);
+ sql2 = malloc(len16 + sizeof(jchar));
+ memcpy(sql2, sql16, len16);
+ sql2[len16 / sizeof(jchar)] = '\0';
+ (*env)->ReleaseStringChars(env, sql, sql16);
#if HAVE_SQLITE3_PREPARE16_V2
- ret = sqlite3_prepare16_v2((sqlite3 *) h->sqlite, sql16, len16,
+ ret = sqlite3_prepare16_v2((sqlite3 *) h->sqlite, sql2, len16,
(sqlite3_stmt **) &svm, (const void **) &tail);
#else
- ret = sqlite3_prepare16((sqlite3 *) h->sqlite, sql16, len16,
+ ret = sqlite3_prepare16((sqlite3 *) h->sqlite, sql2, len16,
(sqlite3_stmt **) &svm, (const void **) &tail);
#endif
if (ret != SQLITE_OK) {
@@ -3401,22 +3407,23 @@
if (ret != SQLITE_OK) {
const char *err = sqlite3_errmsg(h->sqlite);
- (*env)->ReleaseStringChars(env, sql, sql16);
+ free(sql2);
setstmterr(env, stmt, ret);
+ printf("%s\n", err);
throwex(env, err ? err : "error in prepare");
return;
}
if (!svm) {
- (*env)->ReleaseStringChars(env, sql, sql16);
+ free(sql2);
return;
}
- len16 = len16 + sizeof (jchar) - ((char *) tail - (char *) sql16);
+ len16 = len16 + sizeof (jchar) - ((char *) tail - (char *) sql2);
if (len16 < sizeof (jchar)) {
len16 = sizeof (jchar);
}
v = malloc(sizeof (hvm) + len16);
if (!v) {
- (*env)->ReleaseStringChars(env, sql, sql16);
+ free(sql2);
sqlite3_finalize((sqlite3_stmt *) svm);
throwoom(env, "unable to get SQLite handle");
return;
@@ -3432,7 +3439,7 @@
memcpy(v->tail, tail, len16);
len16 /= sizeof (jchar);
((jchar *) v->tail)[len16 - 1] = 0;
- (*env)->ReleaseStringChars(env, sql, sql16);
+ free(sql2);
v->hh.sqlite = 0;
v->hh.haveutf = h->haveutf;
v->hh.ver = h->ver;
|