amalgalite 0.10.1-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +201 -0
- data/LICENSE +29 -0
- data/README +51 -0
- data/bin/amalgalite-pack +126 -0
- data/examples/a.rb +9 -0
- data/examples/blob.rb +88 -0
- data/examples/bootstrap.rb +36 -0
- data/examples/define_aggregate.rb +75 -0
- data/examples/define_function.rb +104 -0
- data/examples/gem-db.rb +94 -0
- data/examples/gems.db +0 -0
- data/examples/require_me.rb +11 -0
- data/examples/requires.rb +42 -0
- data/examples/schema-info.rb +34 -0
- data/ext/amalgalite/amalgalite3.c +290 -0
- data/ext/amalgalite/amalgalite3.h +151 -0
- data/ext/amalgalite/amalgalite3_blob.c +240 -0
- data/ext/amalgalite/amalgalite3_constants.c +221 -0
- data/ext/amalgalite/amalgalite3_database.c +1148 -0
- data/ext/amalgalite/amalgalite3_requires_bootstrap.c +210 -0
- data/ext/amalgalite/amalgalite3_statement.c +639 -0
- data/ext/amalgalite/extconf.rb +36 -0
- data/ext/amalgalite/gen_constants.rb +130 -0
- data/ext/amalgalite/sqlite3.c +106729 -0
- data/ext/amalgalite/sqlite3.h +5626 -0
- data/ext/amalgalite/sqlite3_options.h +4 -0
- data/ext/amalgalite/sqlite3ext.h +380 -0
- data/gemspec.rb +60 -0
- data/lib/amalgalite.rb +43 -0
- data/lib/amalgalite/1.8/amalgalite3.so +0 -0
- data/lib/amalgalite/1.9/amalgalite3.so +0 -0
- data/lib/amalgalite/aggregate.rb +67 -0
- data/lib/amalgalite/blob.rb +186 -0
- data/lib/amalgalite/boolean.rb +42 -0
- data/lib/amalgalite/busy_timeout.rb +47 -0
- data/lib/amalgalite/column.rb +97 -0
- data/lib/amalgalite/core_ext/kernel/require.rb +21 -0
- data/lib/amalgalite/database.rb +947 -0
- data/lib/amalgalite/function.rb +61 -0
- data/lib/amalgalite/index.rb +43 -0
- data/lib/amalgalite/packer.rb +226 -0
- data/lib/amalgalite/paths.rb +70 -0
- data/lib/amalgalite/profile_tap.rb +131 -0
- data/lib/amalgalite/progress_handler.rb +21 -0
- data/lib/amalgalite/requires.rb +120 -0
- data/lib/amalgalite/schema.rb +191 -0
- data/lib/amalgalite/sqlite3.rb +6 -0
- data/lib/amalgalite/sqlite3/constants.rb +80 -0
- data/lib/amalgalite/sqlite3/database/function.rb +48 -0
- data/lib/amalgalite/sqlite3/database/status.rb +68 -0
- data/lib/amalgalite/sqlite3/status.rb +60 -0
- data/lib/amalgalite/sqlite3/version.rb +37 -0
- data/lib/amalgalite/statement.rb +414 -0
- data/lib/amalgalite/table.rb +90 -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 +40 -0
- data/lib/amalgalite/type_maps/text_map.rb +22 -0
- data/lib/amalgalite/version.rb +37 -0
- data/lib/amalgalite/view.rb +26 -0
- data/spec/aggregate_spec.rb +169 -0
- data/spec/amalgalite_spec.rb +4 -0
- data/spec/blob_spec.rb +81 -0
- data/spec/boolean_spec.rb +23 -0
- data/spec/busy_handler.rb +165 -0
- data/spec/database_spec.rb +494 -0
- data/spec/default_map_spec.rb +87 -0
- data/spec/function_spec.rb +94 -0
- data/spec/integeration_spec.rb +111 -0
- data/spec/packer_spec.rb +60 -0
- data/spec/paths_spec.rb +28 -0
- data/spec/progress_handler_spec.rb +105 -0
- data/spec/requires_spec.rb +23 -0
- data/spec/rtree_spec.rb +71 -0
- data/spec/schema_spec.rb +120 -0
- data/spec/spec_helper.rb +27 -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 +53 -0
- data/spec/statement_spec.rb +161 -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 +15 -0
- data/tasks/announce.rake +43 -0
- data/tasks/config.rb +107 -0
- data/tasks/distribution.rake +77 -0
- data/tasks/documentation.rake +32 -0
- data/tasks/extension.rake +141 -0
- data/tasks/rspec.rake +33 -0
- data/tasks/rubyforge.rake +59 -0
- data/tasks/utils.rb +80 -0
- metadata +237 -0
@@ -0,0 +1,151 @@
|
|
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
|
+
#include <string.h>
|
14
|
+
|
15
|
+
/* wrapper struct around the sqlite3 opaque pointer */
|
16
|
+
typedef struct am_sqlite3 {
|
17
|
+
sqlite3 *db;
|
18
|
+
VALUE trace_obj;
|
19
|
+
VALUE profile_obj;
|
20
|
+
VALUE busy_handler_obj;
|
21
|
+
VALUE progress_handler_obj;
|
22
|
+
} am_sqlite3;
|
23
|
+
|
24
|
+
/* wrapper struct around the sqlite3_statement opaque pointer */
|
25
|
+
typedef struct am_sqlite3_stmt {
|
26
|
+
sqlite3_stmt *stmt;
|
27
|
+
VALUE remaining_sql;
|
28
|
+
} am_sqlite3_stmt;
|
29
|
+
|
30
|
+
/* wrapper struct around the sqlite3_blob opaque ponter */
|
31
|
+
typedef struct am_sqlite3_blob {
|
32
|
+
sqlite3_blob *blob;
|
33
|
+
sqlite3 *db;
|
34
|
+
int length;
|
35
|
+
int current_offset;
|
36
|
+
} am_sqlite3_blob;
|
37
|
+
|
38
|
+
/* wrapper struct around the information needed to call rb_apply
|
39
|
+
* used to encapsulate data into a call for amalgalite_wrap_apply
|
40
|
+
*/
|
41
|
+
typedef struct am_protected {
|
42
|
+
VALUE instance;
|
43
|
+
ID method;
|
44
|
+
int argc;
|
45
|
+
VALUE *argv;
|
46
|
+
} am_protected_t;
|
47
|
+
|
48
|
+
/** module and classes **/
|
49
|
+
extern VALUE mA; /* module Amalgalite */
|
50
|
+
extern VALUE mAS; /* module Amalgalite::SQLite3 */
|
51
|
+
extern VALUE mASV; /* module Amalgalite::SQLite3::Version */
|
52
|
+
extern VALUE eAS_Error; /* class Amalgalite::SQLite3::Error */
|
53
|
+
extern VALUE cAR; /* class Amalgalite::Requries */
|
54
|
+
extern VALUE cARB; /* class Amalgalite::Requries::Bootstrap */
|
55
|
+
|
56
|
+
/*----------------------------------------------------------------------
|
57
|
+
* Prototype for Amalgalite::SQLite3::Database
|
58
|
+
*---------------------------------------------------------------------*/
|
59
|
+
extern VALUE cAS_Database; /* class Amalgalite::SQLite3::Database */
|
60
|
+
|
61
|
+
extern void am_define_constants_under(VALUE);
|
62
|
+
extern VALUE am_sqlite3_database_alloc(VALUE klass);
|
63
|
+
extern void am_sqlite3_database_free(am_sqlite3*);
|
64
|
+
extern VALUE am_sqlite3_database_open(int argc, VALUE* argv, VALUE self);
|
65
|
+
extern VALUE am_sqlite3_database_close(VALUE self);
|
66
|
+
extern VALUE am_sqlite3_database_open16(VALUE self, VALUE rFilename);
|
67
|
+
extern VALUE am_sqlite3_database_last_insert_rowid(VALUE self);
|
68
|
+
extern VALUE am_sqlite3_database_is_autocommit(VALUE self);
|
69
|
+
extern VALUE am_sqlite3_database_row_changes(VALUE self);
|
70
|
+
extern VALUE am_sqlite3_database_total_changes(VALUE self);
|
71
|
+
extern VALUE am_sqlite3_database_table_column_metadata(VALUE self, VALUE db_name, VALUE tbl_name, VALUE col_name);
|
72
|
+
|
73
|
+
extern VALUE am_sqlite3_database_prepare(VALUE self, VALUE rSQL);
|
74
|
+
extern VALUE am_sqlite3_database_register_trace_tap(VALUE self, VALUE tap);
|
75
|
+
extern VALUE am_sqlite3_database_register_profile_tap(VALUE self, VALUE tap);
|
76
|
+
extern VALUE am_sqlite3_database_busy_handler(VALUE self, VALUE handler);
|
77
|
+
|
78
|
+
/*----------------------------------------------------------------------
|
79
|
+
* Prototype for Amalgalite::SQLite3::Statement
|
80
|
+
*---------------------------------------------------------------------*/
|
81
|
+
extern VALUE cAS_Statement; /* class Amalgalite::SQLite3::Statement */
|
82
|
+
|
83
|
+
extern VALUE am_sqlite3_statement_alloc(VALUE klass);
|
84
|
+
extern void am_sqlite3_statement_free(am_sqlite3_stmt* );
|
85
|
+
extern VALUE am_sqlite3_statement_sql(VALUE self);
|
86
|
+
extern VALUE am_sqlite3_statement_close(VALUE self);
|
87
|
+
extern VALUE am_sqlite3_statement_step(VALUE self);
|
88
|
+
extern VALUE am_sqlite3_statement_column_count(VALUE self);
|
89
|
+
extern VALUE am_sqlite3_statement_column_name(VALUE self, VALUE index);
|
90
|
+
extern VALUE am_sqlite3_statement_column_decltype(VALUE self, VALUE index);
|
91
|
+
extern VALUE am_sqlite3_statement_column_type(VALUE self, VALUE index);
|
92
|
+
extern VALUE am_sqlite3_statement_column_blob(VALUE self, VALUE index);
|
93
|
+
extern VALUE am_sqlite3_statement_column_text(VALUE self, VALUE index);
|
94
|
+
extern VALUE am_sqlite3_statement_column_int(VALUE self, VALUE index);
|
95
|
+
extern VALUE am_sqlite3_statement_column_int64(VALUE self, VALUE index);
|
96
|
+
extern VALUE am_sqlite3_statement_column_double(VALUE self, VALUE index);
|
97
|
+
|
98
|
+
extern VALUE am_sqlite3_statement_column_database_name(VALUE self, VALUE position);
|
99
|
+
extern VALUE am_sqlite3_statement_column_table_name(VALUE self, VALUE position);
|
100
|
+
extern VALUE am_sqlite3_statement_column_origin_name(VALUE self, VALUE position);
|
101
|
+
|
102
|
+
extern VALUE am_sqlite3_statement_reset(VALUE self);
|
103
|
+
extern VALUE am_sqlite3_statement_clear_bindings(VALUE self);
|
104
|
+
extern VALUE am_sqlite3_statement_bind_parameter_count(VALUE self);
|
105
|
+
extern VALUE am_sqlite3_statement_bind_parameter_index(VALUE self, VALUE parameter_name);
|
106
|
+
extern VALUE am_sqlite3_statement_remaining_sql(VALUE self);
|
107
|
+
extern VALUE am_sqlite3_statement_bind_text(VALUE self, VALUE position, VALUE value);
|
108
|
+
extern VALUE am_sqlite3_statement_bind_blob(VALUE self, VALUE position, VALUE value);
|
109
|
+
extern VALUE am_sqlite3_statement_bind_zeroblob(VALUE self, VALUE position, VALUE value);
|
110
|
+
extern VALUE am_sqlite3_statement_bind_int(VALUE self, VALUE position, VALUE value);
|
111
|
+
extern VALUE am_sqlite3_statement_bind_int64(VALUE self, VALUE position, VALUE value);
|
112
|
+
extern VALUE am_sqlite3_statement_bind_double(VALUE self, VALUE position, VALUE value);
|
113
|
+
extern VALUE am_sqlite3_statement_bind_null(VALUE self, VALUE position);
|
114
|
+
|
115
|
+
/*----------------------------------------------------------------------
|
116
|
+
* Prototype for Amalgalite::SQLite3::Blob
|
117
|
+
*---------------------------------------------------------------------*/
|
118
|
+
extern VALUE cAS_Blob; /* class Amalgalite::SQLite3::Blob */
|
119
|
+
|
120
|
+
extern VALUE am_sqlite3_blob_alloc(VALUE klass);
|
121
|
+
extern VALUE am_sqlite3_blob_initialize( VALUE self, VALUE db, VALUE db_name, VALUE table_name, VALUE column_name, VALUE rowid, VALUE flag) ;
|
122
|
+
extern void am_sqlite3_blob_free(am_sqlite3_blob* );
|
123
|
+
extern VALUE am_sqlite3_blob_read(VALUE self, VALUE length);
|
124
|
+
extern VALUE am_sqlite3_blob_write(VALUE self, VALUE buffer);
|
125
|
+
extern VALUE am_sqlite3_blob_close(VALUE self);
|
126
|
+
extern VALUE am_sqlite3_blob_length(VALUE self);
|
127
|
+
|
128
|
+
/*----------------------------------------------------------------------
|
129
|
+
* more initialization methods
|
130
|
+
*----------------------------------------------------------------------*/
|
131
|
+
extern void Init_amalgalite3_constants( );
|
132
|
+
extern void Init_amalgalite3_database( );
|
133
|
+
extern void Init_amalgalite3_statement( );
|
134
|
+
extern void Init_amalgalite3_blob( );
|
135
|
+
extern void Init_amalgalite3_requires_bootstrap( );
|
136
|
+
|
137
|
+
|
138
|
+
/***********************************************************************
|
139
|
+
* Type conversion macros between sqlite data types and ruby types
|
140
|
+
**********************************************************************/
|
141
|
+
|
142
|
+
#define SQLINT64_2NUM(x) ( LL2NUM( x ) )
|
143
|
+
#define SQLUINT64_2NUM(x) ( ULL2NUM( x ) )
|
144
|
+
#define NUM2SQLINT64( obj ) ( NUM2LL( obj ) )
|
145
|
+
#define NUM2SQLUINT64( obj ) ( NUM2ULL( obj ) )
|
146
|
+
|
147
|
+
/***********************************************************************
|
148
|
+
* return the last exception in ruby's error message
|
149
|
+
*/
|
150
|
+
#define ERROR_INFO_MESSAGE() ( rb_obj_as_string( rb_gv_get("$!") ) )
|
151
|
+
#endif
|
@@ -0,0 +1,240 @@
|
|
1
|
+
#include "amalgalite3.h"
|
2
|
+
/**
|
3
|
+
* Copyright (c) 2008 Jeremy Hinegardner
|
4
|
+
* All rights reserved. See LICENSE and/or COPYING for details.
|
5
|
+
*
|
6
|
+
* vim: shiftwidth=4
|
7
|
+
*/
|
8
|
+
|
9
|
+
/* class Amalgliate::SQLite3::Blob */
|
10
|
+
VALUE cAS_Blob;
|
11
|
+
|
12
|
+
/**
|
13
|
+
* call-seq:
|
14
|
+
* Blob.new( database, table_name, column_name, row_id, flag ) -> Blob
|
15
|
+
*
|
16
|
+
* Create a new Blob object and associate it with the approriate, database,
|
17
|
+
* table, column and row. +flag+ indicates if the Blob is to be opened for
|
18
|
+
* writing "w" or reading "r".
|
19
|
+
*
|
20
|
+
*/
|
21
|
+
VALUE am_sqlite3_blob_initialize( VALUE self, VALUE db, VALUE db_name, VALUE table_name, VALUE column_name, VALUE rowid, VALUE flag)
|
22
|
+
{
|
23
|
+
am_sqlite3_blob *am_blob;
|
24
|
+
int rc;
|
25
|
+
am_sqlite3 *am_db;
|
26
|
+
char *zDb = StringValuePtr( db_name );
|
27
|
+
char *zTable = StringValuePtr( table_name );
|
28
|
+
char *zColumn = StringValuePtr( column_name );
|
29
|
+
sqlite3_int64 iRow = NUM2SQLINT64( rowid ) ;
|
30
|
+
VALUE flag_str = StringValue( flag );
|
31
|
+
int flags = 0;
|
32
|
+
|
33
|
+
/* extract the blob struct */
|
34
|
+
Data_Get_Struct(self, am_sqlite3_blob, am_blob);
|
35
|
+
|
36
|
+
/* extract the sqlite3 db struct */
|
37
|
+
Data_Get_Struct(db, am_sqlite3, am_db);
|
38
|
+
|
39
|
+
/* make sure that the flags are valid, only 'r' or 'w' are allowed */
|
40
|
+
if ( ( RSTRING_LEN( flag_str ) != 1) ||
|
41
|
+
( ( 'r' != RSTRING_PTR( flag_str )[0] ) &&
|
42
|
+
( 'w' != RSTRING_PTR( flag_str )[0] ))) {
|
43
|
+
rb_raise( eAS_Error, "Error opening Blob in db = %s, table = %s, column = %s, rowid = %lu. Invalid flag '%s'. Must be either 'w' or 'r'\n",
|
44
|
+
zDb, zTable, zColumn, (unsigned long)iRow, RSTRING_PTR( flag_str ));
|
45
|
+
}
|
46
|
+
|
47
|
+
/* switch to write mode */
|
48
|
+
if ( 'w' == RSTRING_PTR( flag_str )[0] ) {
|
49
|
+
flags = 1;
|
50
|
+
}
|
51
|
+
|
52
|
+
/* open the blob and associate the db to it */
|
53
|
+
rc = sqlite3_blob_open( am_db->db, zDb, zTable, zColumn, iRow, flags, &( am_blob->blob ) );
|
54
|
+
if ( SQLITE_OK != rc ) {
|
55
|
+
rb_raise( eAS_Error, "Error opening Blob in db = %s, table = %s, column = %s, rowid = %lu : [SQLITE_ERROR %d] %s\n", zDb, zTable, zColumn, (unsigned long)iRow, rc, sqlite3_errmsg( am_db->db) );
|
56
|
+
}
|
57
|
+
am_blob->length = sqlite3_blob_bytes( am_blob->blob );
|
58
|
+
am_blob->db = am_db->db;
|
59
|
+
|
60
|
+
/* if a block is given then yield self and close the blob when done */
|
61
|
+
if ( rb_block_given_p() ) {
|
62
|
+
rb_yield( self );
|
63
|
+
am_sqlite3_blob_close( self );
|
64
|
+
return Qnil;
|
65
|
+
} else {
|
66
|
+
return self;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* call-seq:
|
72
|
+
* blob.close -> nil
|
73
|
+
*
|
74
|
+
* Closes the blob.
|
75
|
+
*/
|
76
|
+
VALUE am_sqlite3_blob_close( VALUE self )
|
77
|
+
{
|
78
|
+
am_sqlite3_blob *am_blob;
|
79
|
+
int rc;
|
80
|
+
|
81
|
+
Data_Get_Struct(self, am_sqlite3_blob, am_blob);
|
82
|
+
rc = sqlite3_blob_close( am_blob->blob );
|
83
|
+
if ( SQLITE_OK != rc ) {
|
84
|
+
rb_raise(eAS_Error, "Error closing blob: [SQLITE_ERROR %d] %s\n",
|
85
|
+
rc, sqlite3_errmsg( am_blob->db ));
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
return Qnil;
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
/**
|
94
|
+
* call-seq:
|
95
|
+
* blob.length -> length in bytes of the blob
|
96
|
+
*
|
97
|
+
* Returns the number of bytes in the blob.
|
98
|
+
*/
|
99
|
+
VALUE am_sqlite3_blob_length( VALUE self )
|
100
|
+
{
|
101
|
+
am_sqlite3_blob *am_blob;
|
102
|
+
|
103
|
+
Data_Get_Struct(self, am_sqlite3_blob, am_blob);
|
104
|
+
|
105
|
+
return INT2FIX( am_blob->length );
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* call-seq:
|
110
|
+
* blob.read( int ) -> String containting int number of bytes or nil if eof.
|
111
|
+
*
|
112
|
+
* returns int number of bytes as a String from the database
|
113
|
+
*/
|
114
|
+
VALUE am_sqlite3_blob_read( VALUE self, VALUE length )
|
115
|
+
{
|
116
|
+
am_sqlite3_blob *am_blob;
|
117
|
+
int rc;
|
118
|
+
int n = NUM2INT( length );
|
119
|
+
void *buf = NULL;
|
120
|
+
VALUE result;
|
121
|
+
|
122
|
+
Data_Get_Struct(self, am_sqlite3_blob, am_blob);
|
123
|
+
|
124
|
+
/* we have to be exact on the number of bytes to read. n + current_offset
|
125
|
+
* cannot be larger than the blob's length
|
126
|
+
*/
|
127
|
+
if ( (n + am_blob->current_offset > am_blob->length)) {
|
128
|
+
n = am_blob->length - am_blob->current_offset;
|
129
|
+
}
|
130
|
+
|
131
|
+
if ( am_blob->current_offset == am_blob->length ) {
|
132
|
+
return Qnil;
|
133
|
+
}
|
134
|
+
|
135
|
+
buf = (void *)malloc( n );
|
136
|
+
rc = sqlite3_blob_read( am_blob->blob, buf, n, am_blob->current_offset);
|
137
|
+
|
138
|
+
if ( rc != SQLITE_OK ) {
|
139
|
+
rb_raise(eAS_Error, "Error reading %d bytes blob at offset %d: [SQLITE_ERROR %d] %s\n",
|
140
|
+
n, am_blob->current_offset, rc, sqlite3_errmsg( am_blob->db ));
|
141
|
+
}
|
142
|
+
|
143
|
+
am_blob->current_offset += n;
|
144
|
+
|
145
|
+
result = rb_str_new( (char*)buf, n );
|
146
|
+
free( buf );
|
147
|
+
return result;
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* call-seq:
|
153
|
+
* blob.write( buf ) -> int
|
154
|
+
*
|
155
|
+
* writes the contents of the string buffer to the blob and returns the number
|
156
|
+
* of bytes written.
|
157
|
+
*
|
158
|
+
*/
|
159
|
+
VALUE am_sqlite3_blob_write( VALUE self, VALUE buf )
|
160
|
+
{
|
161
|
+
am_sqlite3_blob *am_blob;
|
162
|
+
int rc;
|
163
|
+
VALUE str = StringValue( buf );
|
164
|
+
int n = RSTRING_LEN( str );
|
165
|
+
char *chk_buf = NULL;
|
166
|
+
|
167
|
+
Data_Get_Struct(self, am_sqlite3_blob, am_blob);
|
168
|
+
|
169
|
+
rc = sqlite3_blob_write( am_blob->blob, RSTRING_PTR(str), n, am_blob->current_offset);
|
170
|
+
|
171
|
+
if ( rc != SQLITE_OK ) {
|
172
|
+
rb_raise(eAS_Error, "Error writing %d bytes blob at offset %d: [SQLITE_ERROR %d] %s\n",
|
173
|
+
n, am_blob->current_offset, rc, sqlite3_errmsg( am_blob->db ));
|
174
|
+
}
|
175
|
+
|
176
|
+
chk_buf = (char *) malloc( n + 1);
|
177
|
+
chk_buf[n] = '\0';
|
178
|
+
sqlite3_blob_read( am_blob->blob, chk_buf, n, 0);
|
179
|
+
|
180
|
+
am_blob->current_offset += n;
|
181
|
+
|
182
|
+
return INT2FIX( n );
|
183
|
+
|
184
|
+
}
|
185
|
+
|
186
|
+
|
187
|
+
/***********************************************************************
|
188
|
+
* Ruby life cycle methods
|
189
|
+
***********************************************************************/
|
190
|
+
|
191
|
+
/*
|
192
|
+
* garbage collector free method for the am_sqlite3_blob structure
|
193
|
+
*/
|
194
|
+
void am_sqlite3_blob_free(am_sqlite3_blob* wrapper)
|
195
|
+
{
|
196
|
+
free(wrapper);
|
197
|
+
return;
|
198
|
+
}
|
199
|
+
|
200
|
+
/*
|
201
|
+
* allocate the am_blob structure
|
202
|
+
*/
|
203
|
+
VALUE am_sqlite3_blob_alloc(VALUE klass)
|
204
|
+
{
|
205
|
+
am_sqlite3_blob *wrapper = ALLOC( am_sqlite3_blob );
|
206
|
+
VALUE obj ;
|
207
|
+
|
208
|
+
wrapper->current_offset = 0;
|
209
|
+
wrapper->db = NULL;
|
210
|
+
obj = Data_Wrap_Struct(klass, NULL, am_sqlite3_blob_free, wrapper);
|
211
|
+
return obj;
|
212
|
+
}
|
213
|
+
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Document-class: Amalgalite::SQLite3::Blob
|
217
|
+
*
|
218
|
+
* The Blob class enables incremental IO on blob items. If you do not need
|
219
|
+
* incremental IO on a binary object, then you do not need to use Blob.
|
220
|
+
*/
|
221
|
+
|
222
|
+
void Init_amalgalite3_blob( )
|
223
|
+
{
|
224
|
+
|
225
|
+
VALUE ma = rb_define_module("Amalgalite");
|
226
|
+
VALUE mas = rb_define_module_under(ma, "SQLite3");
|
227
|
+
|
228
|
+
/*
|
229
|
+
* Encapsulate the SQLite3 Statement handle in a class
|
230
|
+
*/
|
231
|
+
cAS_Blob = rb_define_class_under( mas, "Blob", rb_cObject );
|
232
|
+
rb_define_alloc_func(cAS_Blob, am_sqlite3_blob_alloc);
|
233
|
+
rb_define_method(cAS_Blob, "initialize", am_sqlite3_blob_initialize, 6);
|
234
|
+
rb_define_method(cAS_Blob, "close", am_sqlite3_blob_close, 0);
|
235
|
+
rb_define_method(cAS_Blob, "read", am_sqlite3_blob_read, 1);
|
236
|
+
rb_define_method(cAS_Blob, "write", am_sqlite3_blob_write, 1);
|
237
|
+
rb_define_method(cAS_Blob, "length", am_sqlite3_blob_length, 0);
|
238
|
+
}
|
239
|
+
|
240
|
+
|
@@ -0,0 +1,221 @@
|
|
1
|
+
/* Generated by gen_constants.rb -- do not edit */
|
2
|
+
|
3
|
+
#include "amalgalite3.h"
|
4
|
+
/**
|
5
|
+
* Document-class: Amalgalite::SQLite3::Constants
|
6
|
+
*
|
7
|
+
* class holding constants in the sqlite extension
|
8
|
+
*/
|
9
|
+
void Init_amalgalite3_constants( )
|
10
|
+
{
|
11
|
+
|
12
|
+
VALUE ma = rb_define_module("Amalgalite");
|
13
|
+
VALUE mas = rb_define_module_under(ma, "SQLite3");
|
14
|
+
|
15
|
+
/*
|
16
|
+
* module encapsulating all the SQLite C extension constants
|
17
|
+
*/
|
18
|
+
VALUE mC = rb_define_module_under( mas, "Constants");
|
19
|
+
/**
|
20
|
+
* module encapsulating the SQLite3 C extension constants for DBStatus
|
21
|
+
*/
|
22
|
+
VALUE mC_DBStatus = rb_define_module_under(mC, "DBStatus");
|
23
|
+
|
24
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
25
|
+
rb_define_const(mC_DBStatus, "LOOKASIDE_USED", INT2FIX(SQLITE_DBSTATUS_LOOKASIDE_USED));
|
26
|
+
|
27
|
+
/**
|
28
|
+
* module encapsulating the SQLite3 C extension constants for DataType
|
29
|
+
*/
|
30
|
+
VALUE mC_DataType = rb_define_module_under(mC, "DataType");
|
31
|
+
|
32
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
33
|
+
rb_define_const(mC_DataType, "BLOB", INT2FIX(SQLITE_BLOB));
|
34
|
+
|
35
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
36
|
+
rb_define_const(mC_DataType, "FLOAT", INT2FIX(SQLITE_FLOAT));
|
37
|
+
|
38
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
39
|
+
rb_define_const(mC_DataType, "INTEGER", INT2FIX(SQLITE_INTEGER));
|
40
|
+
|
41
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
42
|
+
rb_define_const(mC_DataType, "NULL", INT2FIX(SQLITE_NULL));
|
43
|
+
|
44
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
45
|
+
rb_define_const(mC_DataType, "TEXT", INT2FIX(SQLITE_TEXT));
|
46
|
+
|
47
|
+
/**
|
48
|
+
* module encapsulating the SQLite3 C extension constants for Open
|
49
|
+
*/
|
50
|
+
VALUE mC_Open = rb_define_module_under(mC, "Open");
|
51
|
+
|
52
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
53
|
+
rb_define_const(mC_Open, "CREATE", INT2FIX(SQLITE_OPEN_CREATE));
|
54
|
+
|
55
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
56
|
+
rb_define_const(mC_Open, "READONLY", INT2FIX(SQLITE_OPEN_READONLY));
|
57
|
+
|
58
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
59
|
+
rb_define_const(mC_Open, "READWRITE", INT2FIX(SQLITE_OPEN_READWRITE));
|
60
|
+
|
61
|
+
/**
|
62
|
+
* module encapsulating the SQLite3 C extension constants for ResultCode
|
63
|
+
*/
|
64
|
+
VALUE mC_ResultCode = rb_define_module_under(mC, "ResultCode");
|
65
|
+
|
66
|
+
/* 4 -- Callback routine requested an abort */
|
67
|
+
rb_define_const(mC_ResultCode, "ABORT", INT2FIX(SQLITE_ABORT));
|
68
|
+
|
69
|
+
/* 23 -- Authorization denied */
|
70
|
+
rb_define_const(mC_ResultCode, "AUTH", INT2FIX(SQLITE_AUTH));
|
71
|
+
|
72
|
+
/* 5 -- The database file is locked */
|
73
|
+
rb_define_const(mC_ResultCode, "BUSY", INT2FIX(SQLITE_BUSY));
|
74
|
+
|
75
|
+
/* 14 -- Unable to open the database file */
|
76
|
+
rb_define_const(mC_ResultCode, "CANTOPEN", INT2FIX(SQLITE_CANTOPEN));
|
77
|
+
|
78
|
+
/* 19 -- Abort due to constraint violation */
|
79
|
+
rb_define_const(mC_ResultCode, "CONSTRAINT", INT2FIX(SQLITE_CONSTRAINT));
|
80
|
+
|
81
|
+
/* 11 -- The database disk image is malformed */
|
82
|
+
rb_define_const(mC_ResultCode, "CORRUPT", INT2FIX(SQLITE_CORRUPT));
|
83
|
+
|
84
|
+
/* 101 -- sqlite3_step() has finished executing */
|
85
|
+
rb_define_const(mC_ResultCode, "DONE", INT2FIX(SQLITE_DONE));
|
86
|
+
|
87
|
+
/* 16 -- Database is empty */
|
88
|
+
rb_define_const(mC_ResultCode, "EMPTY", INT2FIX(SQLITE_EMPTY));
|
89
|
+
|
90
|
+
/* 1 -- SQL error or missing database */
|
91
|
+
rb_define_const(mC_ResultCode, "ERROR", INT2FIX(SQLITE_ERROR));
|
92
|
+
|
93
|
+
/* 24 -- Auxiliary database format error */
|
94
|
+
rb_define_const(mC_ResultCode, "FORMAT", INT2FIX(SQLITE_FORMAT));
|
95
|
+
|
96
|
+
/* 13 -- Insertion failed because database is full */
|
97
|
+
rb_define_const(mC_ResultCode, "FULL", INT2FIX(SQLITE_FULL));
|
98
|
+
|
99
|
+
/* 2 -- Internal logic error in SQLite */
|
100
|
+
rb_define_const(mC_ResultCode, "INTERNAL", INT2FIX(SQLITE_INTERNAL));
|
101
|
+
|
102
|
+
/* 9 -- Operation terminated by sqlite3_interrupt() */
|
103
|
+
rb_define_const(mC_ResultCode, "INTERRUPT", INT2FIX(SQLITE_INTERRUPT));
|
104
|
+
|
105
|
+
/* 10 -- Some kind of disk I/O error occurred */
|
106
|
+
rb_define_const(mC_ResultCode, "IOERR", INT2FIX(SQLITE_IOERR));
|
107
|
+
|
108
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
109
|
+
rb_define_const(mC_ResultCode, "IOERR_BLOCKED", INT2FIX(SQLITE_IOERR_BLOCKED));
|
110
|
+
|
111
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
112
|
+
rb_define_const(mC_ResultCode, "IOERR_DELETE", INT2FIX(SQLITE_IOERR_DELETE));
|
113
|
+
|
114
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
115
|
+
rb_define_const(mC_ResultCode, "IOERR_DIR_FSYNC", INT2FIX(SQLITE_IOERR_DIR_FSYNC));
|
116
|
+
|
117
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
118
|
+
rb_define_const(mC_ResultCode, "IOERR_FSTAT", INT2FIX(SQLITE_IOERR_FSTAT));
|
119
|
+
|
120
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
121
|
+
rb_define_const(mC_ResultCode, "IOERR_FSYNC", INT2FIX(SQLITE_IOERR_FSYNC));
|
122
|
+
|
123
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
124
|
+
rb_define_const(mC_ResultCode, "IOERR_NOMEM", INT2FIX(SQLITE_IOERR_NOMEM));
|
125
|
+
|
126
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
127
|
+
rb_define_const(mC_ResultCode, "IOERR_RDLOCK", INT2FIX(SQLITE_IOERR_RDLOCK));
|
128
|
+
|
129
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
130
|
+
rb_define_const(mC_ResultCode, "IOERR_READ", INT2FIX(SQLITE_IOERR_READ));
|
131
|
+
|
132
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
133
|
+
rb_define_const(mC_ResultCode, "IOERR_SHORT_READ", INT2FIX(SQLITE_IOERR_SHORT_READ));
|
134
|
+
|
135
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
136
|
+
rb_define_const(mC_ResultCode, "IOERR_TRUNCATE", INT2FIX(SQLITE_IOERR_TRUNCATE));
|
137
|
+
|
138
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
139
|
+
rb_define_const(mC_ResultCode, "IOERR_UNLOCK", INT2FIX(SQLITE_IOERR_UNLOCK));
|
140
|
+
|
141
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
142
|
+
rb_define_const(mC_ResultCode, "IOERR_WRITE", INT2FIX(SQLITE_IOERR_WRITE));
|
143
|
+
|
144
|
+
/* 6 -- A table in the database is locked */
|
145
|
+
rb_define_const(mC_ResultCode, "LOCKED", INT2FIX(SQLITE_LOCKED));
|
146
|
+
|
147
|
+
/* 20 -- Data type mismatch */
|
148
|
+
rb_define_const(mC_ResultCode, "MISMATCH", INT2FIX(SQLITE_MISMATCH));
|
149
|
+
|
150
|
+
/* 21 -- Library used incorrectly */
|
151
|
+
rb_define_const(mC_ResultCode, "MISUSE", INT2FIX(SQLITE_MISUSE));
|
152
|
+
|
153
|
+
/* 22 -- Uses OS features not supported on host */
|
154
|
+
rb_define_const(mC_ResultCode, "NOLFS", INT2FIX(SQLITE_NOLFS));
|
155
|
+
|
156
|
+
/* 7 -- A malloc() failed */
|
157
|
+
rb_define_const(mC_ResultCode, "NOMEM", INT2FIX(SQLITE_NOMEM));
|
158
|
+
|
159
|
+
/* 26 -- File opened that is not a database file */
|
160
|
+
rb_define_const(mC_ResultCode, "NOTADB", INT2FIX(SQLITE_NOTADB));
|
161
|
+
|
162
|
+
/* 12 -- NOT USED. Table or record not found */
|
163
|
+
rb_define_const(mC_ResultCode, "NOTFOUND", INT2FIX(SQLITE_NOTFOUND));
|
164
|
+
|
165
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
166
|
+
rb_define_const(mC_ResultCode, "OK", INT2FIX(SQLITE_OK));
|
167
|
+
|
168
|
+
/* 3 -- Access permission denied */
|
169
|
+
rb_define_const(mC_ResultCode, "PERM", INT2FIX(SQLITE_PERM));
|
170
|
+
|
171
|
+
/* 15 -- NOT USED. Database lock protocol error */
|
172
|
+
rb_define_const(mC_ResultCode, "PROTOCOL", INT2FIX(SQLITE_PROTOCOL));
|
173
|
+
|
174
|
+
/* 25 -- 2nd parameter to sqlite3_bind out of range */
|
175
|
+
rb_define_const(mC_ResultCode, "RANGE", INT2FIX(SQLITE_RANGE));
|
176
|
+
|
177
|
+
/* 8 -- Attempt to write a readonly database */
|
178
|
+
rb_define_const(mC_ResultCode, "READONLY", INT2FIX(SQLITE_READONLY));
|
179
|
+
|
180
|
+
/* 100 -- sqlite3_step() has another row ready */
|
181
|
+
rb_define_const(mC_ResultCode, "ROW", INT2FIX(SQLITE_ROW));
|
182
|
+
|
183
|
+
/* 17 -- The database schema changed */
|
184
|
+
rb_define_const(mC_ResultCode, "SCHEMA", INT2FIX(SQLITE_SCHEMA));
|
185
|
+
|
186
|
+
/* 18 -- String or BLOB exceeds size limit */
|
187
|
+
rb_define_const(mC_ResultCode, "TOOBIG", INT2FIX(SQLITE_TOOBIG));
|
188
|
+
|
189
|
+
/**
|
190
|
+
* module encapsulating the SQLite3 C extension constants for Status
|
191
|
+
*/
|
192
|
+
VALUE mC_Status = rb_define_module_under(mC, "Status");
|
193
|
+
|
194
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
195
|
+
rb_define_const(mC_Status, "MALLOC_SIZE", INT2FIX(SQLITE_STATUS_MALLOC_SIZE));
|
196
|
+
|
197
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
198
|
+
rb_define_const(mC_Status, "MEMORY_USED", INT2FIX(SQLITE_STATUS_MEMORY_USED));
|
199
|
+
|
200
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
201
|
+
rb_define_const(mC_Status, "PAGECACHE_OVERFLOW", INT2FIX(SQLITE_STATUS_PAGECACHE_OVERFLOW));
|
202
|
+
|
203
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
204
|
+
rb_define_const(mC_Status, "PAGECACHE_SIZE", INT2FIX(SQLITE_STATUS_PAGECACHE_SIZE));
|
205
|
+
|
206
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
207
|
+
rb_define_const(mC_Status, "PAGECACHE_USED", INT2FIX(SQLITE_STATUS_PAGECACHE_USED));
|
208
|
+
|
209
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
210
|
+
rb_define_const(mC_Status, "PARSER_STACK", INT2FIX(SQLITE_STATUS_PARSER_STACK));
|
211
|
+
|
212
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
213
|
+
rb_define_const(mC_Status, "SCRATCH_OVERFLOW", INT2FIX(SQLITE_STATUS_SCRATCH_OVERFLOW));
|
214
|
+
|
215
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
216
|
+
rb_define_const(mC_Status, "SCRATCH_SIZE", INT2FIX(SQLITE_STATUS_SCRATCH_SIZE));
|
217
|
+
|
218
|
+
/* no meaningful autogenerated documentation -- constant is self explanatory ?*/
|
219
|
+
rb_define_const(mC_Status, "SCRATCH_USED", INT2FIX(SQLITE_STATUS_SCRATCH_USED));
|
220
|
+
|
221
|
+
}
|