sqlite3-full 1.3.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/API_CHANGES.rdoc +50 -0
- data/CHANGELOG.rdoc +278 -0
- data/ChangeLog.cvs +88 -0
- data/Gemfile +15 -0
- data/LICENSE +34 -0
- data/Manifest.txt +52 -0
- data/README.rdoc +90 -0
- data/Rakefile +10 -0
- data/ext/sqlite3/backup.c +168 -0
- data/ext/sqlite3/backup.h +15 -0
- data/ext/sqlite3/database.c +825 -0
- data/ext/sqlite3/database.h +15 -0
- data/ext/sqlite3/exception.c +94 -0
- data/ext/sqlite3/exception.h +8 -0
- data/ext/sqlite3/extconf.rb +86 -0
- data/ext/sqlite3/sqlite3.c +97 -0
- data/ext/sqlite3/sqlite3_ruby.h +52 -0
- data/ext/sqlite3/sqlite3amalgamation.c +153367 -0
- data/ext/sqlite3/statement.c +447 -0
- data/ext/sqlite3/statement.h +16 -0
- data/faq/faq.rb +145 -0
- data/faq/faq.yml +426 -0
- data/lib/sqlite3/constants.rb +49 -0
- data/lib/sqlite3/database.rb +590 -0
- data/lib/sqlite3/errors.rb +44 -0
- data/lib/sqlite3/pragmas.rb +280 -0
- data/lib/sqlite3/resultset.rb +195 -0
- data/lib/sqlite3/statement.rb +144 -0
- data/lib/sqlite3/translator.rb +118 -0
- data/lib/sqlite3/value.rb +57 -0
- data/lib/sqlite3/version.rb +25 -0
- data/lib/sqlite3.rb +10 -0
- data/setup.rb +1333 -0
- data/tasks/faq.rake +9 -0
- data/tasks/gem.rake +38 -0
- data/tasks/native.rake +52 -0
- data/tasks/vendor_sqlite3.rake +91 -0
- data/test/helper.rb +18 -0
- data/test/test_backup.rb +33 -0
- data/test/test_collation.rb +82 -0
- data/test/test_database.rb +367 -0
- data/test/test_database_readonly.rb +29 -0
- data/test/test_deprecated.rb +44 -0
- data/test/test_encoding.rb +153 -0
- data/test/test_integration.rb +572 -0
- data/test/test_integration_open_close.rb +30 -0
- data/test/test_integration_pending.rb +115 -0
- data/test/test_integration_resultset.rb +159 -0
- data/test/test_integration_statement.rb +194 -0
- data/test/test_result_set.rb +37 -0
- data/test/test_sqlite3.rb +9 -0
- data/test/test_statement.rb +260 -0
- data/test/test_statement_execute.rb +35 -0
- metadata +205 -0
@@ -0,0 +1,168 @@
|
|
1
|
+
#ifdef HAVE_SQLITE3_BACKUP_INIT
|
2
|
+
|
3
|
+
#include <sqlite3_ruby.h>
|
4
|
+
|
5
|
+
#define REQUIRE_OPEN_BACKUP(_ctxt) \
|
6
|
+
if(!_ctxt->p) \
|
7
|
+
rb_raise(rb_path2class("SQLite3::Exception"), "cannot use a closed backup");
|
8
|
+
|
9
|
+
VALUE cSqlite3Backup;
|
10
|
+
|
11
|
+
static void deallocate(void * ctx)
|
12
|
+
{
|
13
|
+
sqlite3BackupRubyPtr c = (sqlite3BackupRubyPtr)ctx;
|
14
|
+
xfree(c);
|
15
|
+
}
|
16
|
+
|
17
|
+
static VALUE allocate(VALUE klass)
|
18
|
+
{
|
19
|
+
sqlite3BackupRubyPtr ctx = xcalloc((size_t)1, sizeof(sqlite3BackupRuby));
|
20
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
|
21
|
+
}
|
22
|
+
|
23
|
+
/* call-seq: SQLite3::Backup.new(dstdb, dstname, srcdb, srcname)
|
24
|
+
*
|
25
|
+
* Initialize backup the backup.
|
26
|
+
*
|
27
|
+
* dstdb:
|
28
|
+
* the destination SQLite3::Database object.
|
29
|
+
* dstname:
|
30
|
+
* the destination's database name.
|
31
|
+
* srcdb:
|
32
|
+
* the source SQLite3::Database object.
|
33
|
+
* srcname:
|
34
|
+
* the source's database name.
|
35
|
+
*
|
36
|
+
* The database name is "main", "temp", or the name specified in an
|
37
|
+
* ATTACH statement.
|
38
|
+
*
|
39
|
+
* This feature requires SQLite 3.6.11 or later.
|
40
|
+
*
|
41
|
+
* require 'sqlite3'
|
42
|
+
* sdb = SQLite3::Database.new('src.sqlite3')
|
43
|
+
*
|
44
|
+
* ddb = SQLite3::Database.new(':memory:')
|
45
|
+
* b = SQLite3::Backup.new(ddb, 'main', sdb, 'main')
|
46
|
+
* p [b.remaining, b.pagecount] # invalid value; for example [0, 0]
|
47
|
+
* begin
|
48
|
+
* p b.step(1) #=> OK or DONE
|
49
|
+
* p [b.remaining, b.pagecount]
|
50
|
+
* end while b.remaining > 0
|
51
|
+
* b.finish
|
52
|
+
*
|
53
|
+
* ddb = SQLite3::Database.new(':memory:')
|
54
|
+
* b = SQLite3::Backup.new(ddb, 'main', sdb, 'main')
|
55
|
+
* b.step(-1) #=> DONE
|
56
|
+
* b.finish
|
57
|
+
*
|
58
|
+
*/
|
59
|
+
static VALUE initialize(VALUE self, VALUE dstdb, VALUE dstname, VALUE srcdb, VALUE srcname)
|
60
|
+
{
|
61
|
+
sqlite3BackupRubyPtr ctx;
|
62
|
+
sqlite3RubyPtr ddb_ctx, sdb_ctx;
|
63
|
+
sqlite3_backup *pBackup;
|
64
|
+
|
65
|
+
Data_Get_Struct(self, sqlite3BackupRuby, ctx);
|
66
|
+
Data_Get_Struct(dstdb, sqlite3Ruby, ddb_ctx);
|
67
|
+
Data_Get_Struct(srcdb, sqlite3Ruby, sdb_ctx);
|
68
|
+
|
69
|
+
if(!sdb_ctx->db)
|
70
|
+
rb_raise(rb_eArgError, "cannot backup from a closed database");
|
71
|
+
if(!ddb_ctx->db)
|
72
|
+
rb_raise(rb_eArgError, "cannot backup to a closed database");
|
73
|
+
|
74
|
+
pBackup = sqlite3_backup_init(ddb_ctx->db, StringValuePtr(dstname),
|
75
|
+
sdb_ctx->db, StringValuePtr(srcname));
|
76
|
+
if( pBackup ){
|
77
|
+
ctx->p = pBackup;
|
78
|
+
}
|
79
|
+
else {
|
80
|
+
CHECK(ddb_ctx->db, sqlite3_errcode(ddb_ctx->db));
|
81
|
+
}
|
82
|
+
|
83
|
+
return self;
|
84
|
+
}
|
85
|
+
|
86
|
+
/* call-seq: SQLite3::Backup#step(nPage)
|
87
|
+
*
|
88
|
+
* Copy database pages up to +nPage+.
|
89
|
+
* If negative, copy all remaining source pages.
|
90
|
+
*
|
91
|
+
* If all pages are copied, it returns SQLite3::Constants::ErrorCode::DONE.
|
92
|
+
* When coping is not done, it returns SQLite3::Constants::ErrorCode::OK.
|
93
|
+
* When some errors occur, it returns the error code.
|
94
|
+
*/
|
95
|
+
static VALUE step(VALUE self, VALUE nPage)
|
96
|
+
{
|
97
|
+
sqlite3BackupRubyPtr ctx;
|
98
|
+
int status;
|
99
|
+
|
100
|
+
Data_Get_Struct(self, sqlite3BackupRuby, ctx);
|
101
|
+
REQUIRE_OPEN_BACKUP(ctx);
|
102
|
+
status = sqlite3_backup_step(ctx->p, NUM2INT(nPage));
|
103
|
+
return INT2NUM(status);
|
104
|
+
}
|
105
|
+
|
106
|
+
/* call-seq: SQLite3::Backup#finish
|
107
|
+
*
|
108
|
+
* Destroy the backup object.
|
109
|
+
*/
|
110
|
+
static VALUE finish(VALUE self)
|
111
|
+
{
|
112
|
+
sqlite3BackupRubyPtr ctx;
|
113
|
+
|
114
|
+
Data_Get_Struct(self, sqlite3BackupRuby, ctx);
|
115
|
+
REQUIRE_OPEN_BACKUP(ctx);
|
116
|
+
(void)sqlite3_backup_finish(ctx->p);
|
117
|
+
ctx->p = NULL;
|
118
|
+
return Qnil;
|
119
|
+
}
|
120
|
+
|
121
|
+
/* call-seq: SQLite3::Backup#remaining
|
122
|
+
*
|
123
|
+
* Returns the number of pages still to be backed up.
|
124
|
+
*
|
125
|
+
* Note that the value is only updated after step() is called,
|
126
|
+
* so before calling step() returned value is invalid.
|
127
|
+
*/
|
128
|
+
static VALUE remaining(VALUE self)
|
129
|
+
{
|
130
|
+
sqlite3BackupRubyPtr ctx;
|
131
|
+
|
132
|
+
Data_Get_Struct(self, sqlite3BackupRuby, ctx);
|
133
|
+
REQUIRE_OPEN_BACKUP(ctx);
|
134
|
+
return INT2NUM(sqlite3_backup_remaining(ctx->p));
|
135
|
+
}
|
136
|
+
|
137
|
+
/* call-seq: SQLite3::Backup#pagecount
|
138
|
+
*
|
139
|
+
* Returns the total number of pages in the source database file.
|
140
|
+
*
|
141
|
+
* Note that the value is only updated after step() is called,
|
142
|
+
* so before calling step() returned value is invalid.
|
143
|
+
*/
|
144
|
+
static VALUE pagecount(VALUE self)
|
145
|
+
{
|
146
|
+
sqlite3BackupRubyPtr ctx;
|
147
|
+
|
148
|
+
Data_Get_Struct(self, sqlite3BackupRuby, ctx);
|
149
|
+
REQUIRE_OPEN_BACKUP(ctx);
|
150
|
+
return INT2NUM(sqlite3_backup_pagecount(ctx->p));
|
151
|
+
}
|
152
|
+
|
153
|
+
void init_sqlite3_backup()
|
154
|
+
{
|
155
|
+
#if 0
|
156
|
+
VALUE mSqlite3 = rb_define_module("SQLite3");
|
157
|
+
#endif
|
158
|
+
cSqlite3Backup = rb_define_class_under(mSqlite3, "Backup", rb_cObject);
|
159
|
+
|
160
|
+
rb_define_alloc_func(cSqlite3Backup, allocate);
|
161
|
+
rb_define_method(cSqlite3Backup, "initialize", initialize, 4);
|
162
|
+
rb_define_method(cSqlite3Backup, "step", step, 1);
|
163
|
+
rb_define_method(cSqlite3Backup, "finish", finish, 0);
|
164
|
+
rb_define_method(cSqlite3Backup, "remaining", remaining, 0);
|
165
|
+
rb_define_method(cSqlite3Backup, "pagecount", pagecount, 0);
|
166
|
+
}
|
167
|
+
|
168
|
+
#endif
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#if !defined(SQLITE3_BACKUP_RUBY) && defined(HAVE_SQLITE3_BACKUP_INIT)
|
2
|
+
#define SQLITE3_BACKUP_RUBY
|
3
|
+
|
4
|
+
#include <sqlite3_ruby.h>
|
5
|
+
|
6
|
+
struct _sqlite3BackupRuby {
|
7
|
+
sqlite3_backup *p;
|
8
|
+
};
|
9
|
+
|
10
|
+
typedef struct _sqlite3BackupRuby sqlite3BackupRuby;
|
11
|
+
typedef sqlite3BackupRuby * sqlite3BackupRubyPtr;
|
12
|
+
|
13
|
+
void init_sqlite3_backup();
|
14
|
+
|
15
|
+
#endif
|