summaryrefslogtreecommitdiffstats
path: root/lib/sqlite3/driver/dl/api.rb
blob: 9cea866f02e15611a432ba6ebd0135a20dcd2176 (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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#--
# =============================================================================
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 
#     * Redistributions of source code must retain the above copyright notice,
#       this list of conditions and the following disclaimer.
# 
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
# 
#     * The names of its contributors may not be used to endorse or promote
#       products derived from this software without specific prior written
#       permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# =============================================================================
#++

require 'dl/import'

module SQLite3 ; module Driver; module DL;

  module API
    extend ::DL::Importable

    library_name = case RUBY_PLATFORM.downcase
      when /darwin/
        "libsqlite3.dylib"
      when /linux/, /freebsd|netbsd|openbsd|dragonfly/, /solaris/
        "libsqlite3.so"
      when /win32/
        "sqlite3.dll"
      else
        abort <<-EOF
== * UNSUPPORTED PLATFORM ======================================================
The platform '#{RUBY_PLATFORM}' is unsupported. Please help the author by
editing the following file to allow your sqlite3 library to be found, and
submitting a patch to jamis_buck@byu.edu. Thanks!

#{__FILE__}
=========================================================================== * ==
        EOF
    end

    if defined? SQLITE3_LIB_PATH
      library_name = File.join( SQLITE3_LIB_PATH, library_name )
    end

    dlload library_name

    typealias "db",      "void*"
    typealias "stmt",    "void*"
    typealias "value",   "void*"
    typealias "context", "void*"

    # until Ruby/DL supports 64-bit ints, we'll just treat them as 32-bit ints
    typealias "int64", "unsigned long"

    extern "const char *sqlite3_libversion()"

    extern "int sqlite3_open(const char*,db*)"
    extern "int sqlite3_open16(const void*,db*)"
    extern "int sqlite3_close(db)"
    extern "const char* sqlite3_errmsg(db)"
    extern "void* sqlite3_errmsg16(db)"
    extern "int sqlite3_errcode(db)"

    extern "int sqlite3_prepare(db,const char*,int,stmt*,const char**)"
    extern "int sqlite3_prepare16(db,const void*,int,stmt*,const void**)"
    extern "int sqlite3_finalize(stmt)"
    extern "int sqlite3_reset(stmt)"
    extern "int sqlite3_step(stmt)"

    extern "int64 sqlite3_last_insert_rowid(db)"
    extern "int sqlite3_changes(db)"
    extern "int sqlite3_total_changes(db)"
    extern "void sqlite3_interrupt(db)"
    extern "ibool sqlite3_complete(const char*)"
    extern "ibool sqlite3_complete16(const void*)"

    extern "int sqlite3_busy_handler(db,void*,void*)"
    extern "int sqlite3_busy_timeout(db,int)"

    extern "int sqlite3_set_authorizer(db,void*,void*)"
    extern "void* sqlite3_trace(db,void*,void*)"

    extern "int sqlite3_bind_blob(stmt,int,const void*,int,void*)"
    extern "int sqlite3_bind_double(stmt,int,double)"
    extern "int sqlite3_bind_int(stmt,int,int)"
    extern "int sqlite3_bind_int64(stmt,int,int64)"
    extern "int sqlite3_bind_null(stmt,int)"
    extern "int sqlite3_bind_text(stmt,int,const char*,int,void*)"
    extern "int sqlite3_bind_text16(stmt,int,const void*,int,void*)"
    #extern "int sqlite3_bind_value(stmt,int,value)"

    extern "int sqlite3_bind_parameter_count(stmt)"
    extern "const char* sqlite3_bind_parameter_name(stmt,int)"
    extern "int sqlite3_bind_parameter_index(stmt,const char*)"

    extern "int sqlite3_column_count(stmt)"
    extern "int sqlite3_data_count(stmt)"

    extern "const void *sqlite3_column_blob(stmt,int)"
    extern "int sqlite3_column_bytes(stmt,int)"
    extern "int sqlite3_column_bytes16(stmt,int)"
    extern "const char *sqlite3_column_decltype(stmt,int)"
    extern "void *sqlite3_column_decltype16(stmt,int)"
    extern "double sqlite3_column_double(stmt,int)"
    extern "int sqlite3_column_int(stmt,int)"
    extern "int64 sqlite3_column_int64(stmt,int)"
    extern "const char *sqlite3_column_name(stmt,int)"
    extern "const void *sqlite3_column_name16(stmt,int)"
    extern "const char *sqlite3_column_text(stmt,int)"
    extern "const void *sqlite3_column_text16(stmt,int)"
    extern "int sqlite3_column_type(stmt,int)"

    extern "int sqlite3_create_function(db,const char*,int,int,void*,void*,void*,void*)"
    extern "int sqlite3_create_function16(db,const void*,int,int,void*,void*,void*,void*)"
    extern "int sqlite3_aggregate_count(context)"

    extern "const void *sqlite3_value_blob(value)"
    extern "int sqlite3_value_bytes(value)"
    extern "int sqlite3_value_bytes16(value)"
    extern "double sqlite3_value_double(value)"
    extern "int sqlite3_value_int(value)"
    extern "int64 sqlite3_value_int64(value)"
    extern "const char* sqlite3_value_text(value)"
    extern "const void* sqlite3_value_text16(value)"
    extern "const void* sqlite3_value_text16le(value)"
    extern "const void* sqlite3_value_text16be(value)"
    extern "int sqlite3_value_type(value)"

    extern "void *sqlite3_aggregate_context(context,int)"
    extern "void *sqlite3_user_data(context)"
    extern "void *sqlite3_get_auxdata(context,int)"
    extern "void sqlite3_set_auxdata(context,int,void*,void*)"

    extern "void sqlite3_result_blob(context,const void*,int,void*)"
    extern "void sqlite3_result_double(context,double)"
    extern "void sqlite3_result_error(context,const char*,int)"
    extern "void sqlite3_result_error16(context,const void*,int)"
    extern "void sqlite3_result_int(context,int)"
    extern "void sqlite3_result_int64(context,int64)"
    extern "void sqlite3_result_null(context)"
    extern "void sqlite3_result_text(context,const char*,int,void*)"
    extern "void sqlite3_result_text16(context,const void*,int,void*)"
    extern "void sqlite3_result_text16le(context,const void*,int,void*)"
    extern "void sqlite3_result_text16be(context,const void*,int,void*)"
    extern "void sqlite3_result_value(context,value)"

    extern "int sqlite3_create_collation(db,const char*,int,void*,void*)"
    extern "int sqlite3_create_collation16(db,const char*,int,void*,void*)"
    extern "int sqlite3_collation_needed(db,void*,void*)"
    extern "int sqlite3_collation_needed16(db,void*,void*)"

    # ==== CRYPTO (NOT IN PUBLIC RELEASE) ====
    if defined?( CRYPTO_API ) && CRYPTO_API
      extern "int sqlite3_key(db,void*,int)"
      extern "int sqlite3_rekey(db,void*,int)"
    end

    # ==== EXPERIMENTAL ====
    if defined?( EXPERIMENTAL_API ) && EXPERIMENTAL_API
      extern "int sqlite3_progress_handler(db,int,void*,void*)"
      extern "int sqlite3_commit_hook(db,void*,void*)"
    end

  end

end ; end ; end