Newer
Older
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
#include <glib.h>
#include <sqlite3.h>
static void
test_string_escape ()
{
const char* phrase1 = "nihao";
char* quoted = sqlite3_mprintf("%Q", phrase1);
g_assert_cmpstr (quoted, ==, "'nihao'");
sqlite3_free (quoted);
const char* phrase2 = "ni'hao";
quoted = sqlite3_mprintf("%Q", phrase2);
g_assert_cmpstr (quoted, ==, "'ni''hao'");
sqlite3_free (quoted);
const char* phrase3 = "'nihao'";
quoted = sqlite3_mprintf("%Q", phrase3);
g_assert_cmpstr (quoted, ==, "'''nihao'''");
sqlite3_free (quoted);
const char* phrase4 = "英国";
quoted = sqlite3_mprintf("%Q", phrase4);
g_assert_cmpstr (quoted, ==, "'英国'");
sqlite3_free (quoted);
const char* phrase5 = "英';drop国";
quoted = sqlite3_mprintf("%Q", phrase5);
g_assert_cmpstr (quoted, ==, "'英'';drop国'");
sqlite3_free (quoted);
}
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/Database/string-escape",
test_string_escape);
return g_test_run ();
}