summaryrefslogtreecommitdiff
path: root/examples/sql/c/README
blob: a64cec6741cfa268ca93eee59655ce884bd1755f (plain)
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
Examples for SQL
================
a) Common files:
1.ex_sql_utils.c/h:    common utils

b) There are 8 INDEPENDENT examples. They are NOT interdependent and only 
   based on above common utils:
1.ex_sql_load:          create table, insert, load csv files
2.ex_sql_query:         select, order by, group by, subquery, SQL function
3.ex_sql_index:         index, query explain
4.ex_sql_statment:      prepare, iterate results, callback function
5.ex_sql_transaction:   transaction, commit, rollback
6.ex_sql_savepoint:     savepoint
7.ex_sql_multi_thread:  multi-thread, transaction
8.ex_sql_binding:       prepare, variable binding, transaction, bulk insert
9.ex_sql_fts3:		full-text search features
10.ex_sql_rtree:        create, maintain, and query r-tree index

c) Sample data source:
1.university.csv:       Sample data of table university
2.country.csv:          Sample data of table country
3.sms.csv:		Sample data of table sms

Run Instructions
================
UNIX/Linux platform:
1. Build db sql
  - cd <db>/build_unix
  - ../dist/configure --enable-sql --enable-test --with-tcl=/usr/lib<or your 
    tcl path which include tclConfig.sh>. To run ex_sql_fts3, SQLITE_ENABLE_FTS3
    need to be added in CPPFLAGS so the fts3 extension could be included.To run 
    ex_sql_rtree, SQLITE_ENABLE_RTREE need to be added in CPPFLAGS so the rtree
    extension could be included.
  - make dbsql
2. Build c examples
  - make ex_sql_load
  - make ex_sql_index
  - ...
3. Executing
  These examples must be executed on <db>/build_unx
  - ./ex_sql_load
  - ./ex_sql_index
  - ...

Windows:
1. Use Visual Studio to build example project ex_sql_* in BerkeleyDB.sln. To 
run ex_sql_fts3, all source code and head files under <db>/sql/sqlite/ext/fts3
need to be added to db_sql project and "/D SQLITE_ENABLE_FTS3" needs to be 
specified in the project's C/C++ command line. To run ex_sql_rtree,
"/D SQLITE_ENABLE_RTREE" needs to be specified in db_sql project, and
db/sql/sqlite/ext/rtree/rtree.c should be added in.
2. Work on command line to run(say above build option is Win32|Release):
- cd <db>/build_windows
- Win32\Release\ex_sql_load (or other examples)


Common Behaviors of Examples
============================
1. Data Source
All examples data is stored in files *.csv. The location is db/sqlite/examples/data.

2. Exception Handler
To simplify the examples we use a common exception handling function
error_handler(db_handle*) in ex_sql_utils.c. It reports an error message and 
exits if any unexpected error occurs. Most of the examples which do not 
require individualized error handler can use this common handler for 
convenience. 

3. Common SQL Executor
The function exec_sql(db_handle* db, const char* sql) in ex_sql_utils.c can 
execute a given sql expression and print results automatically. It also calls 
upon the common exception handler.