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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
#include "ex_sql_utils.h"
/*
* This example demonstrates the usage of full-text search.
* Example 1: Query by rowid.
* Example 2: Full-text Query.
* Example 3: Token prefix query.
* Example 4: Table column specified token query.
* Example 5: Phrase query.
* Example 6: Using operator.
* Example 7: NEAR query.
* Example 8: Using auxiliary functions.
*/
const sample_data sms_sample_data = {
"sms",
"\tDROP TABLE IF EXISTS sms;\n"
"\tCREATE VIRTUAL TABLE sms\n"
"\tUSING fts3(\n"
"\t\tnumber varchar(10) NOT NULL,\n"
"\t\tname varchar(20),\n"
"\t\tcontent TEXT\n"
"\t, tokenize=simple);",
"../examples/sql/data/sms.csv", 3};
/* Example body. */
static int
ex_sql_fts3(db)
db_handle *db;
{
const char* sql;
/*
* Example 1: Query by rowid.
*/
echo_info("Example 1: Query by rowid.");
sql = "SELECT rowid, * FROM sms WHERE rowid=10;";
exec_sql(db, sql);
/*
* Example 2: Full-text Query.
*/
echo_info("Example 2: Full-text Query.");
sql = "SELECT * FROM sms WHERE name MATCH 'Aaron';";
exec_sql(db, sql);
/*
* Example 3: Token prefix query.
*/
echo_info("Example 3: Token prefix query.");
sql = "SELECT * FROM sms WHERE sms MATCH 'Jack*';";
exec_sql(db, sql);
/*
* Example 4: Table column specified token query.
*/
echo_info("Example 4: Table column specified token query.");
sql = "SELECT * FROM sms WHERE content match 'name:Demitrius grey';";
exec_sql(db, sql);
/*
* Example 5: Phrase query.
*/
echo_info("Example 5: Phrase query.");
sql = "SELECT * FROM sms WHERE content MATCH '\"eag* beav*\"';";
exec_sql(db, sql);
/*
* Example 6: Using operator.
*/
echo_info("Example 6: Using operator.");
sql = "SELECT * FROM sms WHERE sms MATCH 'Hedin AND english';";
exec_sql(db, sql);
/*
* Example 7: NEAR query.
*/
echo_info("Example 7: NEAR query.");
sql = "SELECT * FROM sms WHERE sms MATCH 'clear NEAR/2 air';";
exec_sql(db, sql);
/*
* Example 8: Using auxiliary functions.
*/
echo_info("Example 8: Using auxiliary functions.");
sql = "SELECT snippet(sms) FROM sms WHERE sms MATCH 'Elymas';";
exec_sql(db, sql);
return 0;
}
int
main()
{
db_handle *db;
/* Setup environment and preload data. */
db = setup("./ex_sql_fts3.db");
load_table_from_file(db, sms_sample_data, 1);
/* Run example. */
ex_sql_fts3(db);
/* End. */
cleanup(db);
return 0;
}
|