amalgalite 0.4.2-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +81 -0
- data/LICENSE +29 -0
- data/README +40 -0
- data/bin/amalgalite-pack-into-db +155 -0
- data/examples/a.rb +9 -0
- data/examples/blob.rb +105 -0
- data/examples/bootstrap.rb +36 -0
- data/examples/gem-db.rb +94 -0
- data/examples/requires.rb +54 -0
- data/examples/schema-info.rb +34 -0
- data/ext/amalgalite3.c +201 -0
- data/ext/amalgalite3.h +121 -0
- data/ext/amalgalite3_blob.c +241 -0
- data/ext/amalgalite3_constants.c +221 -0
- data/ext/amalgalite3_database.c +550 -0
- data/ext/amalgalite3_requires_bootstrap.c +210 -0
- data/ext/amalgalite3_statement.c +628 -0
- data/ext/extconf.rb +19 -0
- data/ext/gen_constants.rb +130 -0
- data/ext/rbconfig-mingw.rb +178 -0
- data/ext/sqlite3.c +97092 -0
- data/ext/sqlite3.h +6364 -0
- data/ext/sqlite3_options.h +4 -0
- data/ext/sqlite3ext.h +372 -0
- data/gemspec.rb +55 -0
- data/lib/amalgalite.rb +33 -0
- data/lib/amalgalite/blob.rb +186 -0
- data/lib/amalgalite/boolean.rb +42 -0
- data/lib/amalgalite/column.rb +86 -0
- data/lib/amalgalite/core_ext/kernel/require.rb +14 -0
- data/lib/amalgalite/database.rb +514 -0
- data/lib/amalgalite/index.rb +43 -0
- data/lib/amalgalite/paths.rb +70 -0
- data/lib/amalgalite/profile_tap.rb +130 -0
- data/lib/amalgalite/requires.rb +112 -0
- data/lib/amalgalite/schema.rb +115 -0
- data/lib/amalgalite/sqlite3.rb +6 -0
- data/lib/amalgalite/sqlite3/constants.rb +82 -0
- data/lib/amalgalite/sqlite3/database/status.rb +69 -0
- data/lib/amalgalite/sqlite3/status.rb +61 -0
- data/lib/amalgalite/sqlite3/version.rb +38 -0
- data/lib/amalgalite/statement.rb +394 -0
- data/lib/amalgalite/table.rb +36 -0
- data/lib/amalgalite/taps.rb +2 -0
- data/lib/amalgalite/taps/console.rb +27 -0
- data/lib/amalgalite/taps/io.rb +71 -0
- data/lib/amalgalite/trace_tap.rb +35 -0
- data/lib/amalgalite/type_map.rb +63 -0
- data/lib/amalgalite/type_maps/default_map.rb +167 -0
- data/lib/amalgalite/type_maps/storage_map.rb +41 -0
- data/lib/amalgalite/type_maps/text_map.rb +23 -0
- data/lib/amalgalite/version.rb +37 -0
- data/lib/amalgalite/view.rb +26 -0
- data/lib/amalgalite3.so +0 -0
- data/spec/amalgalite_spec.rb +4 -0
- data/spec/blob_spec.rb +81 -0
- data/spec/boolean_spec.rb +23 -0
- data/spec/database_spec.rb +238 -0
- data/spec/default_map_spec.rb +87 -0
- data/spec/integeration_spec.rb +111 -0
- data/spec/paths_spec.rb +28 -0
- data/spec/schema_spec.rb +60 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/sqlite3/constants_spec.rb +65 -0
- data/spec/sqlite3/database_status_spec.rb +36 -0
- data/spec/sqlite3/status_spec.rb +18 -0
- data/spec/sqlite3/version_spec.rb +14 -0
- data/spec/sqlite3_spec.rb +23 -0
- data/spec/statement_spec.rb +134 -0
- data/spec/storage_map_spec.rb +41 -0
- data/spec/tap_spec.rb +59 -0
- data/spec/text_map_spec.rb +23 -0
- data/spec/type_map_spec.rb +17 -0
- data/spec/version_spec.rb +9 -0
- data/tasks/announce.rake +39 -0
- data/tasks/config.rb +110 -0
- data/tasks/distribution.rake +53 -0
- data/tasks/documentation.rake +33 -0
- data/tasks/extension.rake +100 -0
- data/tasks/rspec.rake +32 -0
- data/tasks/rubyforge.rake +59 -0
- data/tasks/utils.rb +80 -0
- metadata +192 -0
data/examples/gem-db.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# Basic amalgalite example creating a table, inserting rows and doing various
|
5
|
+
# selects and prepared statements
|
6
|
+
#
|
7
|
+
require 'rubygems'
|
8
|
+
require 'amalgalite'
|
9
|
+
|
10
|
+
#
|
11
|
+
# Create a database, this will create the DB if it doesn't exist
|
12
|
+
#
|
13
|
+
puts "Opening database (version #{Amalgalite::Version})"
|
14
|
+
db = Amalgalite::Database.new("gems.db")
|
15
|
+
|
16
|
+
#
|
17
|
+
# Setup taps into profile and trace information of sqlite, the profile tap will
|
18
|
+
# goto the profile_tap.log file and the trace information will go to the
|
19
|
+
# trace_tap.log file
|
20
|
+
#
|
21
|
+
puts "Establishing taps"
|
22
|
+
db.trace_tap = Amalgalite::Taps::IO.new( trace_tap_file = File.open("trace_tap.log", "w+") )
|
23
|
+
db.profile_tap = Amalgalite::Taps::IO.new( profile_tap_file = File.open("profile_tap.log", "w+") )
|
24
|
+
|
25
|
+
#
|
26
|
+
# Create the schema unless it already exists in the table. The meta information
|
27
|
+
# about the database schema is available as the result of the db.schema method
|
28
|
+
#
|
29
|
+
schema = db.schema
|
30
|
+
unless schema.tables['gems']
|
31
|
+
puts "Create schema"
|
32
|
+
db.execute <<-SQL
|
33
|
+
CREATE TABLE gems (
|
34
|
+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
35
|
+
name VARCHAR(128),
|
36
|
+
version VARCHAR(32),
|
37
|
+
author VARCHAR(128)
|
38
|
+
);
|
39
|
+
SQL
|
40
|
+
db.reload_schema!
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Get some data from the system to insert into the database. Since everyone
|
45
|
+
# probably has gems installed, that's a ready known piece of information. We'll
|
46
|
+
# just pull in the latest version of each installed gem and dump some meta
|
47
|
+
# information into a db for testing.
|
48
|
+
#
|
49
|
+
latest_specs = Gem.source_index.latest_specs
|
50
|
+
|
51
|
+
puts "Inserting #{latest_specs.size} rows of gem information..."
|
52
|
+
before = Time.now
|
53
|
+
|
54
|
+
# Inserting bulk rows as a transaction is good practice with SQLite, it is
|
55
|
+
# MUCH faster.
|
56
|
+
db.transaction do |db_in_transaction|
|
57
|
+
db_in_transaction.prepare("INSERT INTO gems(name, version, author) VALUES( :name, :version, :author );") do |stmt|
|
58
|
+
latest_specs.each do |spec|
|
59
|
+
insert_data = {}
|
60
|
+
insert_data[':name'] = spec.name.to_s
|
61
|
+
insert_data[':version'] = spec.version.to_s
|
62
|
+
insert_data[':author'] = spec.authors.join(' ')
|
63
|
+
#puts "Inserting #{insert_data.inspect}"
|
64
|
+
stmt.execute( insert_data )
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
puts "Took #{Time.now - before} seconds"
|
69
|
+
puts "Done Inserting"
|
70
|
+
|
71
|
+
authors_by_number = db.execute("SELECT author, count( name ) as num_gems FROM gems GROUP BY author ORDER BY num_gems DESC")
|
72
|
+
favorite_author = authors_by_number.first
|
73
|
+
puts "Your favorite gem author is <#{favorite_author['author']}>, with #{favorite_author['num_gems']} gems installed."
|
74
|
+
|
75
|
+
#
|
76
|
+
# Now we'll look at the profile sampler and see what information it traced about
|
77
|
+
# our behavoir.
|
78
|
+
#
|
79
|
+
db.profile_tap.samplers.each do |stat_name, stat_values|
|
80
|
+
puts "-" * 20
|
81
|
+
puts stat_values.to_s
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# Clear out the taps (not really necessary, just cleaning up)
|
86
|
+
#
|
87
|
+
db.trace_tap = profile_tap = nil
|
88
|
+
|
89
|
+
#
|
90
|
+
# close things down
|
91
|
+
#
|
92
|
+
db.close
|
93
|
+
trace_tap_file.close
|
94
|
+
profile_tap_file.close
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# An Amalgalite example showing how to 'require' data in an amalgalite database
|
5
|
+
#
|
6
|
+
# We'll make a database with one table, that we store file contents in.
|
7
|
+
#
|
8
|
+
|
9
|
+
$: << "../lib"
|
10
|
+
$: << "../ext"
|
11
|
+
require 'rubygems'
|
12
|
+
require 'amalgalite'
|
13
|
+
|
14
|
+
#
|
15
|
+
# create the database
|
16
|
+
#
|
17
|
+
File.unlink( "lib.db" ) if File.exist?( "lib.db" )
|
18
|
+
db = Amalgalite::Database.new( "lib.db" )
|
19
|
+
STDERR.puts "Creating rubylibs table"
|
20
|
+
db.execute(<<-create)
|
21
|
+
CREATE TABLE rubylibs(
|
22
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
23
|
+
filename VARCHAR UNIQUE,
|
24
|
+
contents TEXT
|
25
|
+
)
|
26
|
+
create
|
27
|
+
|
28
|
+
|
29
|
+
#
|
30
|
+
# insert some source code into a row
|
31
|
+
#
|
32
|
+
db.execute("INSERT INTO rubylibs(filename, contents) VALUES ( $filename, $contents )",
|
33
|
+
{ "$filename" => "example",
|
34
|
+
"$contents" => <<code
|
35
|
+
class ExampleCode
|
36
|
+
def initialize( x )
|
37
|
+
puts "Initializing ExampleCode"
|
38
|
+
@x = x
|
39
|
+
end
|
40
|
+
|
41
|
+
def foo
|
42
|
+
puts @x
|
43
|
+
end
|
44
|
+
end
|
45
|
+
code
|
46
|
+
})
|
47
|
+
db.close
|
48
|
+
|
49
|
+
require 'amalgalite/requires'
|
50
|
+
Amalgalite::Requires.new( :dbfile_name => "lib.db" )
|
51
|
+
require 'example'
|
52
|
+
e = ExampleCode.new( 'it works!' )
|
53
|
+
e.foo
|
54
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'amalgalite'
|
5
|
+
|
6
|
+
db_name = ARGV.shift
|
7
|
+
unless db_name
|
8
|
+
puts "Usage: #{File.basename($0)} dbname"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
db = Amalgalite::Database.new( db_name )
|
12
|
+
col_info = %w[ default_value declared_data_type collation_sequence_name not_null_constraint primary_key auto_increment ]
|
13
|
+
max_width = col_info.collect { |c| c.length }.sort.last
|
14
|
+
|
15
|
+
db.schema.tables.keys.sort.each do |table_name|
|
16
|
+
puts "Table: #{table_name}"
|
17
|
+
puts "=" * 42
|
18
|
+
db.schema.tables[table_name].columns.each_pair do |col_name, col|
|
19
|
+
puts " Column : #{col.name}"
|
20
|
+
col_info.each do |ci|
|
21
|
+
puts " |#{ci.rjust( max_width, "." )} : #{col.send( ci )}"
|
22
|
+
end
|
23
|
+
puts
|
24
|
+
end
|
25
|
+
|
26
|
+
db.schema.tables[table_name].indexes.each_pair do |idx_name, index|
|
27
|
+
puts " Index : #{index.name}"
|
28
|
+
puts " |#{"sequence_number".rjust( max_width, "." )} : #{index.sequence_number}"
|
29
|
+
puts " |#{"is unique?".rjust( max_width, ".")} : #{index.unique?}"
|
30
|
+
puts " |#{"columns".rjust( max_width, ".")} : #{index.columns.collect { |c| c.name }.join(',') }"
|
31
|
+
puts
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
data/ext/amalgalite3.c
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2008 Jeremy Hinegardner
|
3
|
+
* All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
*
|
5
|
+
* vim: shiftwidth=4
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include "amalgalite3.h"
|
9
|
+
|
10
|
+
/* Module and Classes */
|
11
|
+
VALUE mA; /* module Amalgalite */
|
12
|
+
VALUE mAS; /* module Amalgalite::SQLite3 */
|
13
|
+
VALUE mASV; /* module Amalgalite::SQLite3::Version */
|
14
|
+
VALUE eAS_Error; /* class Amalgalite::SQLite3::Error */
|
15
|
+
VALUE cAS_Stat; /* class Amalgalite::SQLite3::Stat */
|
16
|
+
|
17
|
+
/*----------------------------------------------------------------------
|
18
|
+
* module methods for Amalgalite::SQLite3
|
19
|
+
*---------------------------------------------------------------------*/
|
20
|
+
|
21
|
+
/*
|
22
|
+
* call-seq:
|
23
|
+
* Amalgalite::SQLite3.threadsafe? -> true or false
|
24
|
+
*
|
25
|
+
* Has the SQLite3 extension been compiled "threadsafe". If threadsafe? is
|
26
|
+
* true then the internal SQLite mutexes are enabled and SQLite is threadsafe.
|
27
|
+
* That is threadsafe within the context of 'C' threads.
|
28
|
+
*
|
29
|
+
*/
|
30
|
+
VALUE am_sqlite3_threadsafe(VALUE self)
|
31
|
+
{
|
32
|
+
if (sqlite3_threadsafe()) {
|
33
|
+
return Qtrue;
|
34
|
+
} else {
|
35
|
+
return Qfalse;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
/*
|
40
|
+
* call-seq:
|
41
|
+
* Amalgalite::SQLite3.complete?( ... , opts = { :utf16 => false }) -> True, False
|
42
|
+
*
|
43
|
+
* Is the text passed in as a parameter a complete SQL statement? Or is
|
44
|
+
* additional input required before sending the SQL to the extension. If the
|
45
|
+
* extra 'opts' parameter is used, you can send in a UTF-16 encoded string as
|
46
|
+
* the SQL.
|
47
|
+
*
|
48
|
+
* A complete statement must end with a semicolon.
|
49
|
+
*
|
50
|
+
*/
|
51
|
+
VALUE am_sqlite3_complete(VALUE self, VALUE args)
|
52
|
+
{
|
53
|
+
VALUE sql = rb_ary_shift( args );
|
54
|
+
VALUE opts = rb_ary_shift( args );
|
55
|
+
VALUE utf16 = Qnil;
|
56
|
+
int result = 0;
|
57
|
+
|
58
|
+
if ( ( Qnil != opts ) && ( T_HASH == TYPE(opts) ) ){
|
59
|
+
utf16 = rb_hash_aref( opts, rb_intern("utf16") );
|
60
|
+
}
|
61
|
+
|
62
|
+
if ( (Qfalse == utf16) || (Qnil == utf16) ) {
|
63
|
+
result = sqlite3_complete( StringValuePtr( sql ) );
|
64
|
+
} else {
|
65
|
+
result = sqlite3_complete16( (void*) StringValuePtr( sql ) );
|
66
|
+
}
|
67
|
+
|
68
|
+
return ( result > 0 ) ? Qtrue : Qfalse;
|
69
|
+
}
|
70
|
+
|
71
|
+
/*
|
72
|
+
* call-seq:
|
73
|
+
* Amalgalite::SQLite3::Stat.update!( reset = false ) -> nil
|
74
|
+
*
|
75
|
+
* Populates the _@current_ and _@higwater_ instance variables of self
|
76
|
+
* object with the values from the sqlite3_status call. If reset it true then
|
77
|
+
* the highwater mark for the stat is reset
|
78
|
+
*
|
79
|
+
*/
|
80
|
+
VALUE am_sqlite3_stat_update_bang( int argc, VALUE *argv, VALUE self )
|
81
|
+
{
|
82
|
+
int status_op = -1;
|
83
|
+
int current = -1;
|
84
|
+
int highwater = -1;
|
85
|
+
VALUE reset = Qfalse;
|
86
|
+
int reset_flag = 0;
|
87
|
+
int rc;
|
88
|
+
|
89
|
+
status_op = FIX2INT( rb_iv_get( self, "@code" ) );
|
90
|
+
if ( argc > 0 ) {
|
91
|
+
reset = argv[0];
|
92
|
+
reset_flag = ( Qtrue == reset ) ? 1 : 0 ;
|
93
|
+
}
|
94
|
+
|
95
|
+
rc = sqlite3_status( status_op, ¤t, &highwater, reset_flag );
|
96
|
+
|
97
|
+
if ( SQLITE_OK != rc ) {
|
98
|
+
VALUE n = rb_iv_get( self, "@name" ) ;
|
99
|
+
char* name = StringValuePtr( n );
|
100
|
+
rb_raise(eAS_Error, "Failure to retrieve status for %s : [SQLITE_ERROR %d] \n", name, rc);
|
101
|
+
}
|
102
|
+
|
103
|
+
rb_iv_set( self, "@current", INT2NUM( current ) );
|
104
|
+
rb_iv_set( self, "@highwater", INT2NUM( highwater) );
|
105
|
+
|
106
|
+
return Qnil;
|
107
|
+
}
|
108
|
+
|
109
|
+
/*
|
110
|
+
* call-seq:
|
111
|
+
* Amalgalite::SQLite3.randomness( N ) -> String of length N
|
112
|
+
*
|
113
|
+
* Generate N bytes of random data.
|
114
|
+
*
|
115
|
+
*/
|
116
|
+
VALUE am_sqlite3_randomness(VALUE self, VALUE num_bytes)
|
117
|
+
{
|
118
|
+
int n = NUM2INT(num_bytes);
|
119
|
+
char *buf = ALLOCA_N(char, n);
|
120
|
+
|
121
|
+
sqlite3_randomness( n, buf );
|
122
|
+
return rb_str_new( buf, n );
|
123
|
+
}
|
124
|
+
|
125
|
+
/*----------------------------------------------------------------------
|
126
|
+
* module methods for Amalgalite::SQLite3::Version
|
127
|
+
*---------------------------------------------------------------------*/
|
128
|
+
|
129
|
+
/*
|
130
|
+
* call-seq:
|
131
|
+
* Amalgalite::SQLite3::Version.to_s -> String
|
132
|
+
*
|
133
|
+
* Return the SQLite C library version number as a string
|
134
|
+
*
|
135
|
+
*/
|
136
|
+
VALUE am_sqlite3_libversion(VALUE self)
|
137
|
+
{
|
138
|
+
return rb_str_new2(sqlite3_libversion());
|
139
|
+
}
|
140
|
+
|
141
|
+
/*
|
142
|
+
* call-seq:
|
143
|
+
* Amalgalite::SQLite3.Version.to_i -> Fixnum
|
144
|
+
*
|
145
|
+
* Return the SQLite C library version number as an integer
|
146
|
+
*
|
147
|
+
*/
|
148
|
+
VALUE am_sqlite3_libversion_number(VALUE self)
|
149
|
+
{
|
150
|
+
return INT2FIX(sqlite3_libversion_number());
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Document-class: Amalgalite::SQLite3
|
155
|
+
*
|
156
|
+
* The SQLite ruby extension inside Amalgalite.
|
157
|
+
*
|
158
|
+
*/
|
159
|
+
|
160
|
+
void Init_amalgalite3()
|
161
|
+
{
|
162
|
+
/*
|
163
|
+
* top level module encapsulating the entire Amalgalite library
|
164
|
+
*/
|
165
|
+
mA = rb_define_module("Amalgalite");
|
166
|
+
|
167
|
+
mAS = rb_define_module_under(mA, "SQLite3");
|
168
|
+
rb_define_module_function(mAS, "threadsafe?", am_sqlite3_threadsafe, 0);
|
169
|
+
rb_define_module_function(mAS, "complete?", am_sqlite3_complete, -2);
|
170
|
+
rb_define_module_function(mAS, "randomness", am_sqlite3_randomness,1);
|
171
|
+
|
172
|
+
/*
|
173
|
+
* class encapsulating a single Stat
|
174
|
+
*/
|
175
|
+
cAS_Stat = rb_define_class_under(mAS, "Stat", rb_cObject);
|
176
|
+
rb_define_method(cAS_Stat, "update!", am_sqlite3_stat_update_bang, -1);
|
177
|
+
|
178
|
+
/*
|
179
|
+
* Base class of all SQLite3 errors
|
180
|
+
*/
|
181
|
+
eAS_Error = rb_define_class_under(mAS, "Error", rb_eStandardError); /* in amalgalite.c */
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Encapsulation of the SQLite C library version
|
185
|
+
*/
|
186
|
+
mASV = rb_define_module_under(mAS, "Version");
|
187
|
+
rb_define_module_function(mASV, "to_s", am_sqlite3_libversion, 0); /* in amalgalite3.c */
|
188
|
+
rb_define_module_function(mASV, "to_i", am_sqlite3_libversion_number, 0); /* in amalgalite3.c */
|
189
|
+
|
190
|
+
/*
|
191
|
+
* Initialize the rest of the module
|
192
|
+
*/
|
193
|
+
Init_amalgalite3_constants( );
|
194
|
+
Init_amalgalite3_database( );
|
195
|
+
Init_amalgalite3_statement( );
|
196
|
+
Init_amalgalite3_blob( );
|
197
|
+
Init_amalgalite3_requires_bootstrap( );
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
data/ext/amalgalite3.h
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2008 Jeremy Hinegardner
|
3
|
+
* All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
*
|
5
|
+
* vim: shiftwidth=4
|
6
|
+
*/
|
7
|
+
|
8
|
+
#ifndef __AMALGALITE_H__
|
9
|
+
#define __AMALGALITE_H__
|
10
|
+
|
11
|
+
#include "ruby.h"
|
12
|
+
#include "sqlite3.h"
|
13
|
+
|
14
|
+
/* wrapper struct around the sqlite3 opaque pointer */
|
15
|
+
typedef struct am_sqlite3 {
|
16
|
+
sqlite3 *db;
|
17
|
+
VALUE trace_obj;
|
18
|
+
VALUE profile_obj;
|
19
|
+
} am_sqlite3;
|
20
|
+
|
21
|
+
/* wrapper struct around the sqlite3_statement opaque pointer */
|
22
|
+
typedef struct am_sqlite3_stmt {
|
23
|
+
sqlite3_stmt *stmt;
|
24
|
+
VALUE remaining_sql;
|
25
|
+
} am_sqlite3_stmt;
|
26
|
+
|
27
|
+
/* wrapper struct around the sqlite3_blob opaque ponter */
|
28
|
+
typedef struct am_sqlite3_blob {
|
29
|
+
sqlite3_blob *blob;
|
30
|
+
sqlite3 *db;
|
31
|
+
int length;
|
32
|
+
int current_offset;
|
33
|
+
} am_sqlite3_blob;
|
34
|
+
|
35
|
+
|
36
|
+
/** module and classes **/
|
37
|
+
extern VALUE mA; /* module Amalgalite */
|
38
|
+
extern VALUE mAS; /* module Amalgalite::SQLite3 */
|
39
|
+
extern VALUE mASV; /* module Amalgalite::SQLite3::Version */
|
40
|
+
extern VALUE eAS_Error; /* class Amalgalite::SQLite3::Error */
|
41
|
+
|
42
|
+
/*----------------------------------------------------------------------
|
43
|
+
* Prototype for Amalgalite::SQLite3::Database
|
44
|
+
*---------------------------------------------------------------------*/
|
45
|
+
extern VALUE cAS_Database; /* class Amalgliate::SQLite3::Database */
|
46
|
+
|
47
|
+
extern void am_define_constants_under(VALUE);
|
48
|
+
extern VALUE am_sqlite3_database_alloc(VALUE klass);
|
49
|
+
extern void am_sqlite3_database_free(am_sqlite3*);
|
50
|
+
extern VALUE am_sqlite3_database_open(int argc, VALUE* argv, VALUE self);
|
51
|
+
extern VALUE am_sqlite3_database_close(VALUE self);
|
52
|
+
extern VALUE am_sqlite3_database_open16(VALUE self, VALUE rFilename);
|
53
|
+
extern VALUE am_sqlite3_database_last_insert_rowid(VALUE self);
|
54
|
+
extern VALUE am_sqlite3_database_is_autocommit(VALUE self);
|
55
|
+
extern VALUE am_sqlite3_database_row_changes(VALUE self);
|
56
|
+
extern VALUE am_sqlite3_database_total_changes(VALUE self);
|
57
|
+
extern VALUE am_sqlite3_database_table_column_metadata(VALUE self, VALUE db_name, VALUE tbl_name, VALUE col_name);
|
58
|
+
|
59
|
+
extern VALUE am_sqlite3_database_prepare(VALUE self, VALUE rSQL);
|
60
|
+
extern VALUE am_sqlite3_database_register_trace_tap(VALUE self, VALUE tap);
|
61
|
+
extern VALUE am_sqlite3_database_register_profile_tap(VALUE self, VALUE tap);
|
62
|
+
|
63
|
+
/*----------------------------------------------------------------------
|
64
|
+
* Prototype for Amalgalite::SQLite3::Statement
|
65
|
+
*---------------------------------------------------------------------*/
|
66
|
+
extern VALUE cAS_Statement; /* class Amalgalite::SQLite3::Statement */
|
67
|
+
|
68
|
+
extern VALUE am_sqlite3_statement_alloc(VALUE klass);
|
69
|
+
extern void am_sqlite3_statement_free(am_sqlite3_stmt* );
|
70
|
+
extern VALUE am_sqlite3_statement_sql(VALUE self);
|
71
|
+
extern VALUE am_sqlite3_statement_close(VALUE self);
|
72
|
+
extern VALUE am_sqlite3_statement_step(VALUE self);
|
73
|
+
extern VALUE am_sqlite3_statement_column_count(VALUE self);
|
74
|
+
extern VALUE am_sqlite3_statement_column_name(VALUE self, VALUE index);
|
75
|
+
extern VALUE am_sqlite3_statement_column_decltype(VALUE self, VALUE index);
|
76
|
+
extern VALUE am_sqlite3_statement_column_type(VALUE self, VALUE index);
|
77
|
+
extern VALUE am_sqlite3_statement_column_blob(VALUE self, VALUE index);
|
78
|
+
extern VALUE am_sqlite3_statement_column_text(VALUE self, VALUE index);
|
79
|
+
extern VALUE am_sqlite3_statement_column_int(VALUE self, VALUE index);
|
80
|
+
extern VALUE am_sqlite3_statement_column_int64(VALUE self, VALUE index);
|
81
|
+
extern VALUE am_sqlite3_statement_column_double(VALUE self, VALUE index);
|
82
|
+
|
83
|
+
extern VALUE am_sqlite3_statement_column_database_name(VALUE self, VALUE position);
|
84
|
+
extern VALUE am_sqlite3_statement_column_table_name(VALUE self, VALUE position);
|
85
|
+
extern VALUE am_sqlite3_statement_column_origin_name(VALUE self, VALUE position);
|
86
|
+
|
87
|
+
extern VALUE am_sqlite3_statement_reset(VALUE self);
|
88
|
+
extern VALUE am_sqlite3_statement_clear_bindings(VALUE self);
|
89
|
+
extern VALUE am_sqlite3_statement_bind_parameter_count(VALUE self);
|
90
|
+
extern VALUE am_sqlite3_statement_bind_parameter_index(VALUE self, VALUE parameter_name);
|
91
|
+
extern VALUE am_sqlite3_statement_remaining_sql(VALUE self);
|
92
|
+
extern VALUE am_sqlite3_statement_bind_text(VALUE self, VALUE position, VALUE value);
|
93
|
+
extern VALUE am_sqlite3_statement_bind_blob(VALUE self, VALUE position, VALUE value);
|
94
|
+
extern VALUE am_sqlite3_statement_bind_zeroblob(VALUE self, VALUE position, VALUE value);
|
95
|
+
extern VALUE am_sqlite3_statement_bind_int(VALUE self, VALUE position, VALUE value);
|
96
|
+
extern VALUE am_sqlite3_statement_bind_int64(VALUE self, VALUE position, VALUE value);
|
97
|
+
extern VALUE am_sqlite3_statement_bind_double(VALUE self, VALUE position, VALUE value);
|
98
|
+
extern VALUE am_sqlite3_statement_bind_null(VALUE self, VALUE position);
|
99
|
+
|
100
|
+
/*----------------------------------------------------------------------
|
101
|
+
* Prototype for Amalgalite::SQLite3::Blob
|
102
|
+
*---------------------------------------------------------------------*/
|
103
|
+
extern VALUE cAS_Blob; /* class Amalgalite::SQLite3::Blob */
|
104
|
+
|
105
|
+
extern VALUE am_sqlite3_blob_alloc(VALUE klass);
|
106
|
+
extern VALUE am_sqlite3_blob_initialize( VALUE self, VALUE db, VALUE db_name, VALUE table_name, VALUE column_name, VALUE rowid, VALUE flag) ;
|
107
|
+
extern void am_sqlite3_blob_free(am_sqlite3_blob* );
|
108
|
+
extern VALUE am_sqlite3_blob_read(VALUE self, VALUE length);
|
109
|
+
extern VALUE am_sqlite3_blob_write(VALUE self, VALUE buffer);
|
110
|
+
extern VALUE am_sqlite3_blob_close(VALUE self);
|
111
|
+
extern VALUE am_sqlite3_blob_length(VALUE self);
|
112
|
+
|
113
|
+
/***********************************************************************
|
114
|
+
* Type conversion macros between sqlite data types and ruby types
|
115
|
+
**********************************************************************/
|
116
|
+
|
117
|
+
#define SQLINT64_2NUM(x) ( LL2NUM( x ) )
|
118
|
+
#define SQLUINT64_2NUM(x) ( ULL2NUM( x ) )
|
119
|
+
#define NUM2SQLINT64( obj ) ( NUM2LL( obj ) )
|
120
|
+
#define NUM2SQLUINT64( obj ) ( NUM2ULL( obj ) )
|
121
|
+
#endif
|