rhodes-framework 1.0.10 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/Manifest.txt +159 -30
  2. data/Rakefile +3 -19
  3. data/lib/erb.rb +1 -1
  4. data/lib/rho/rho.rb +94 -107
  5. data/lib/rho/rhofsconnector.rb +4 -0
  6. data/lib/rho/rhoutils.rb +26 -0
  7. data/lib/rho/rhoviewhelpers.rb +1 -1
  8. data/lib/rhodes.rb +2 -2
  9. data/lib/rhoframework.rb +9 -9
  10. data/lib/rhom/rhom.rb +1 -1
  11. data/lib/rhom/rhom_db_adapter.rb +36 -15
  12. data/lib/rhom/rhom_db_adapterME.rb +2 -3
  13. data/lib/rhom/rhom_object.rb +14 -2
  14. data/lib/rhom/rhom_object_factory.rb +42 -11
  15. data/lib/version.rb +2 -2
  16. data/spec/README +1 -0
  17. data/spec/Rakefile +1 -0
  18. data/spec/{configs/account.rb → app/Account/config.rb} +0 -0
  19. data/spec/{configs/case.rb → app/Case/config.rb} +0 -0
  20. data/spec/app/Question/config.rb +3 -0
  21. data/spec/app/Settings/controller.rb +10 -0
  22. data/spec/app/Settings/index.erb +11 -0
  23. data/spec/app/SpecRunner/controller.rb +15 -0
  24. data/spec/app/SpecRunner/index.erb +14 -0
  25. data/spec/app/application.rb +4 -0
  26. data/spec/app/index.erb +17 -0
  27. data/spec/app/layout.erb +27 -0
  28. data/spec/app/loading.html +11 -0
  29. data/spec/app/mspec.rb +11 -0
  30. data/spec/app/mspec/expectations.rb +2 -0
  31. data/spec/app/mspec/expectations/expectations.rb +17 -0
  32. data/spec/app/mspec/expectations/should.rb +25 -0
  33. data/spec/app/mspec/fileutils.rb +1590 -0
  34. data/spec/app/mspec/guards.rb +16 -0
  35. data/spec/app/mspec/guards/background.rb +21 -0
  36. data/spec/app/mspec/guards/bug.rb +24 -0
  37. data/spec/app/mspec/guards/compliance.rb +37 -0
  38. data/spec/app/mspec/guards/conflict.rb +18 -0
  39. data/spec/app/mspec/guards/endian.rb +44 -0
  40. data/spec/app/mspec/guards/extensions.rb +20 -0
  41. data/spec/app/mspec/guards/guard.rb +166 -0
  42. data/spec/app/mspec/guards/noncompliance.rb +20 -0
  43. data/spec/app/mspec/guards/platform.rb +43 -0
  44. data/spec/app/mspec/guards/quarantine.rb +17 -0
  45. data/spec/app/mspec/guards/runner.rb +34 -0
  46. data/spec/app/mspec/guards/superuser.rb +17 -0
  47. data/spec/app/mspec/guards/support.rb +20 -0
  48. data/spec/app/mspec/guards/tty.rb +20 -0
  49. data/spec/app/mspec/guards/version.rb +38 -0
  50. data/spec/app/mspec/helpers.rb +11 -0
  51. data/spec/app/mspec/helpers/argv.rb +43 -0
  52. data/spec/app/mspec/helpers/bignum.rb +5 -0
  53. data/spec/app/mspec/helpers/const_lookup.rb +9 -0
  54. data/spec/app/mspec/helpers/environment.rb +23 -0
  55. data/spec/app/mspec/helpers/fixture.rb +20 -0
  56. data/spec/app/mspec/helpers/flunk.rb +5 -0
  57. data/spec/app/mspec/helpers/io.rb +17 -0
  58. data/spec/app/mspec/helpers/language_version.rb +20 -0
  59. data/spec/app/mspec/helpers/ruby_exe.rb +123 -0
  60. data/spec/app/mspec/helpers/scratch.rb +17 -0
  61. data/spec/app/mspec/helpers/tmp.rb +32 -0
  62. data/spec/app/mspec/matchers.rb +23 -0
  63. data/spec/app/mspec/matchers/base.rb +95 -0
  64. data/spec/app/mspec/matchers/be_an_instance_of.rb +26 -0
  65. data/spec/app/mspec/matchers/be_ancestor_of.rb +24 -0
  66. data/spec/app/mspec/matchers/be_close.rb +27 -0
  67. data/spec/app/mspec/matchers/be_empty.rb +20 -0
  68. data/spec/app/mspec/matchers/be_false.rb +20 -0
  69. data/spec/app/mspec/matchers/be_kind_of.rb +24 -0
  70. data/spec/app/mspec/matchers/be_nil.rb +20 -0
  71. data/spec/app/mspec/matchers/be_true.rb +20 -0
  72. data/spec/app/mspec/matchers/complain.rb +56 -0
  73. data/spec/app/mspec/matchers/eql.rb +26 -0
  74. data/spec/app/mspec/matchers/equal.rb +26 -0
  75. data/spec/app/mspec/matchers/equal_element.rb +78 -0
  76. data/spec/app/mspec/matchers/equal_utf16.rb +34 -0
  77. data/spec/app/mspec/matchers/have_constant.rb +30 -0
  78. data/spec/app/mspec/matchers/have_instance_method.rb +24 -0
  79. data/spec/app/mspec/matchers/have_method.rb +24 -0
  80. data/spec/app/mspec/matchers/have_private_instance_method.rb +24 -0
  81. data/spec/app/mspec/matchers/include.rb +32 -0
  82. data/spec/app/mspec/matchers/match_yaml.rb +47 -0
  83. data/spec/app/mspec/matchers/method.rb +14 -0
  84. data/spec/app/mspec/matchers/output.rb +67 -0
  85. data/spec/app/mspec/matchers/output_to_fd.rb +71 -0
  86. data/spec/app/mspec/matchers/raise_error.rb +48 -0
  87. data/spec/app/mspec/matchers/respond_to.rb +24 -0
  88. data/spec/app/mspec/matchers/stringsymboladapter.rb +8 -0
  89. data/spec/app/mspec/mocks.rb +3 -0
  90. data/spec/app/mspec/mocks/mock.rb +159 -0
  91. data/spec/app/mspec/mocks/object.rb +20 -0
  92. data/spec/app/mspec/mocks/proxy.rb +136 -0
  93. data/spec/app/mspec/pp.rb +893 -0
  94. data/spec/app/mspec/runner.rb +15 -0
  95. data/spec/app/mspec/runner/actions.rb +8 -0
  96. data/spec/app/mspec/runner/actions/debug.rb +17 -0
  97. data/spec/app/mspec/runner/actions/filter.rb +40 -0
  98. data/spec/app/mspec/runner/actions/gdb.rb +17 -0
  99. data/spec/app/mspec/runner/actions/tag.rb +133 -0
  100. data/spec/app/mspec/runner/actions/taglist.rb +56 -0
  101. data/spec/app/mspec/runner/actions/tagpurge.rb +56 -0
  102. data/spec/app/mspec/runner/actions/tally.rb +116 -0
  103. data/spec/app/mspec/runner/actions/timer.rb +22 -0
  104. data/spec/app/mspec/runner/context.rb +188 -0
  105. data/spec/app/mspec/runner/example.rb +34 -0
  106. data/spec/app/mspec/runner/exception.rb +43 -0
  107. data/spec/app/mspec/runner/filters.rb +4 -0
  108. data/spec/app/mspec/runner/filters/match.rb +22 -0
  109. data/spec/app/mspec/runner/filters/profile.rb +54 -0
  110. data/spec/app/mspec/runner/filters/regexp.rb +7 -0
  111. data/spec/app/mspec/runner/filters/tag.rb +29 -0
  112. data/spec/app/mspec/runner/formatters.rb +10 -0
  113. data/spec/app/mspec/runner/formatters/describe.rb +24 -0
  114. data/spec/app/mspec/runner/formatters/dotted.rb +98 -0
  115. data/spec/app/mspec/runner/formatters/file.rb +19 -0
  116. data/spec/app/mspec/runner/formatters/html.rb +81 -0
  117. data/spec/app/mspec/runner/formatters/method.rb +93 -0
  118. data/spec/app/mspec/runner/formatters/specdoc.rb +41 -0
  119. data/spec/app/mspec/runner/formatters/spinner.rb +99 -0
  120. data/spec/app/mspec/runner/formatters/summary.rb +11 -0
  121. data/spec/app/mspec/runner/formatters/unit.rb +21 -0
  122. data/spec/app/mspec/runner/formatters/yaml.rb +44 -0
  123. data/spec/app/mspec/runner/mspec.rb +361 -0
  124. data/spec/app/mspec/runner/object.rb +24 -0
  125. data/spec/app/mspec/runner/shared.rb +12 -0
  126. data/spec/app/mspec/runner/tag.rb +32 -0
  127. data/spec/app/mspec/utils/name_map.rb +129 -0
  128. data/spec/app/mspec/utils/options.rb +441 -0
  129. data/spec/app/mspec/utils/ruby_name.rb +8 -0
  130. data/spec/app/mspec/utils/script.rb +220 -0
  131. data/spec/app/mspec/utils/version.rb +53 -0
  132. data/spec/app/mspec/version.rb +5 -0
  133. data/spec/app/spec/fixtures/client_info.txt +2 -0
  134. data/spec/app/spec/fixtures/object_values.txt +90 -0
  135. data/spec/{rho_controller_spec.rb → app/spec/rho_controller_spec.rb} +4 -7
  136. data/spec/{rho_spec.rb → app/spec/rho_spec.rb} +15 -36
  137. data/spec/{rhom_object_factory_spec.rb → app/spec/rhom_object_factory_spec.rb} +108 -72
  138. data/spec/{rhom_spec.rb → app/spec/rhom_spec.rb} +8 -4
  139. data/spec/app/spec/spec_helper.rb +15 -0
  140. data/spec/app/spec/webview_spec.rb +27 -0
  141. data/spec/app/spec_runner.rb +26 -0
  142. data/spec/build.yml +28 -0
  143. data/spec/public/css/base.css +39 -0
  144. data/spec/public/css/blackberry.css +99 -0
  145. data/spec/public/css/iphone.css +392 -0
  146. data/spec/public/css/rho.css +3 -0
  147. data/spec/public/css/xhtml.css +114 -0
  148. data/spec/public/images/IUI_LICENSE.txt +21 -0
  149. data/spec/public/images/backButton.png +0 -0
  150. data/spec/public/images/blueButton.png +0 -0
  151. data/spec/public/images/cancel.png +0 -0
  152. data/spec/public/images/grayButton.png +0 -0
  153. data/spec/public/images/iui-logo-touch-icon.png +0 -0
  154. data/spec/public/images/listArrow.png +0 -0
  155. data/spec/public/images/listArrowSel.png +0 -0
  156. data/spec/public/images/listGroup.png +0 -0
  157. data/spec/public/images/loading.gif +0 -0
  158. data/spec/public/images/pinstripes.png +0 -0
  159. data/spec/public/images/right_button.png +0 -0
  160. data/spec/public/images/selection.png +0 -0
  161. data/spec/public/images/thumb.png +0 -0
  162. data/spec/public/images/toggle.png +0 -0
  163. data/spec/public/images/toggleOn.png +0 -0
  164. data/spec/public/images/toolButton.png +0 -0
  165. data/spec/public/images/toolButton_new.png +0 -0
  166. data/spec/public/images/toolbar.png +0 -0
  167. data/spec/public/images/whiteButton.png +0 -0
  168. data/spec/public/js/application.js +1 -0
  169. data/spec/public/js/jquery-1.2.6.min.js +32 -0
  170. data/spec/public/js/rho.js +4 -0
  171. data/spec/public/js/rhogeolocation-wm.js +59 -0
  172. data/spec/public/js/rhogeolocation.js +11 -0
  173. data/spec/rhoconfig.txt +19 -0
  174. metadata +169 -39
  175. data/History.txt +0 -37
  176. data/README.rdoc +0 -2
  177. data/lib/TestServe.rb +0 -9
  178. data/res/sqlite3/constants.rb +0 -49
  179. data/res/sqlite3/database.rb +0 -715
  180. data/res/sqlite3/driver/dl/api.rb +0 -154
  181. data/res/sqlite3/driver/dl/driver.rb +0 -307
  182. data/res/sqlite3/driver/native/driver.rb +0 -257
  183. data/res/sqlite3/errors.rb +0 -68
  184. data/res/sqlite3/pragmas.rb +0 -271
  185. data/res/sqlite3/resultset.rb +0 -176
  186. data/res/sqlite3/sqlite3_api.rb +0 -0
  187. data/res/sqlite3/statement.rb +0 -230
  188. data/res/sqlite3/translator.rb +0 -109
  189. data/res/sqlite3/value.rb +0 -57
  190. data/res/sqlite3/version.rb +0 -14
  191. data/rhodes.gemspec +0 -18
  192. data/spec/app_manifest.txt +0 -4
  193. data/spec/configs/contact.rb +0 -3
  194. data/spec/configs/employee.rb +0 -3
  195. data/spec/spec.opts +0 -1
  196. data/spec/spec_helper.rb +0 -49
  197. data/spec/stubs.rb +0 -39
  198. data/spec/syncdbtest.sqlite +0 -0
@@ -1,154 +0,0 @@
1
- require 'dl/import'
2
-
3
- module SQLite3 ; module Driver; module DL;
4
-
5
- module API
6
- extend ::DL::Importable
7
-
8
- puts "RUBY_PLATFORM.downcase = " + RUBY_PLATFORM.downcase
9
-
10
- library_name = case RUBY_PLATFORM.downcase
11
- when /darwin/
12
- "libsqlite3.dylib"
13
- when /linux/, /freebsd|netbsd|openbsd|dragonfly/, /solaris/
14
- "libsqlite3.so"
15
- when /win32/
16
- "sqlite3.dll"
17
- else
18
- abort <<-EOF
19
- == * UNSUPPORTED PLATFORM ======================================================
20
- The platform '#{RUBY_PLATFORM}' is unsupported. Please help the author by
21
- editing the following file to allow your sqlite3 library to be found, and
22
- submitting a patch to jamis_buck@byu.edu. Thanks!
23
-
24
- #{__FILE__}
25
- =========================================================================== * ==
26
- EOF
27
- end
28
-
29
- if defined? SQLITE3_LIB_PATH
30
- library_name = File.join( SQLITE3_LIB_PATH, library_name )
31
- end
32
-
33
- dlload library_name
34
-
35
- typealias "db", "void*"
36
- typealias "stmt", "void*"
37
- typealias "value", "void*"
38
- typealias "context", "void*"
39
-
40
- # until Ruby/DL supports 64-bit ints, we'll just treat them as 32-bit ints
41
- typealias "int64", "unsigned long"
42
-
43
- extern "const char *sqlite3_libversion()"
44
-
45
- extern "int sqlite3_open(const char*,db*)"
46
- extern "int sqlite3_open16(const void*,db*)"
47
- extern "int sqlite3_close(db)"
48
- extern "const char* sqlite3_errmsg(db)"
49
- extern "void* sqlite3_errmsg16(db)"
50
- extern "int sqlite3_errcode(db)"
51
-
52
- extern "int sqlite3_prepare(db,const char*,int,stmt*,const char**)"
53
- extern "int sqlite3_prepare16(db,const void*,int,stmt*,const void**)"
54
- extern "int sqlite3_finalize(stmt)"
55
- extern "int sqlite3_reset(stmt)"
56
- extern "int sqlite3_step(stmt)"
57
-
58
- extern "int64 sqlite3_last_insert_rowid(db)"
59
- extern "int sqlite3_changes(db)"
60
- extern "int sqlite3_total_changes(db)"
61
- extern "void sqlite3_interrupt(db)"
62
- extern "ibool sqlite3_complete(const char*)"
63
- extern "ibool sqlite3_complete16(const void*)"
64
-
65
- extern "int sqlite3_busy_handler(db,void*,void*)"
66
- extern "int sqlite3_busy_timeout(db,int)"
67
-
68
- extern "int sqlite3_set_authorizer(db,void*,void*)"
69
- extern "void* sqlite3_trace(db,void*,void*)"
70
-
71
- extern "int sqlite3_bind_blob(stmt,int,const void*,int,void*)"
72
- extern "int sqlite3_bind_double(stmt,int,double)"
73
- extern "int sqlite3_bind_int(stmt,int,int)"
74
- extern "int sqlite3_bind_int64(stmt,int,int64)"
75
- extern "int sqlite3_bind_null(stmt,int)"
76
- extern "int sqlite3_bind_text(stmt,int,const char*,int,void*)"
77
- extern "int sqlite3_bind_text16(stmt,int,const void*,int,void*)"
78
- #extern "int sqlite3_bind_value(stmt,int,value)"
79
-
80
- extern "int sqlite3_bind_parameter_count(stmt)"
81
- extern "const char* sqlite3_bind_parameter_name(stmt,int)"
82
- extern "int sqlite3_bind_parameter_index(stmt,const char*)"
83
-
84
- extern "int sqlite3_column_count(stmt)"
85
- extern "int sqlite3_data_count(stmt)"
86
-
87
- extern "const void *sqlite3_column_blob(stmt,int)"
88
- extern "int sqlite3_column_bytes(stmt,int)"
89
- extern "int sqlite3_column_bytes16(stmt,int)"
90
- extern "const char *sqlite3_column_decltype(stmt,int)"
91
- extern "void *sqlite3_column_decltype16(stmt,int)"
92
- extern "double sqlite3_column_double(stmt,int)"
93
- extern "int sqlite3_column_int(stmt,int)"
94
- extern "int64 sqlite3_column_int64(stmt,int)"
95
- extern "const char *sqlite3_column_name(stmt,int)"
96
- extern "const void *sqlite3_column_name16(stmt,int)"
97
- extern "const char *sqlite3_column_text(stmt,int)"
98
- extern "const void *sqlite3_column_text16(stmt,int)"
99
- extern "int sqlite3_column_type(stmt,int)"
100
-
101
- extern "int sqlite3_create_function(db,const char*,int,int,void*,void*,void*,void*)"
102
- extern "int sqlite3_create_function16(db,const void*,int,int,void*,void*,void*,void*)"
103
- extern "int sqlite3_aggregate_count(context)"
104
-
105
- extern "const void *sqlite3_value_blob(value)"
106
- extern "int sqlite3_value_bytes(value)"
107
- extern "int sqlite3_value_bytes16(value)"
108
- extern "double sqlite3_value_double(value)"
109
- extern "int sqlite3_value_int(value)"
110
- extern "int64 sqlite3_value_int64(value)"
111
- extern "const char* sqlite3_value_text(value)"
112
- extern "const void* sqlite3_value_text16(value)"
113
- extern "const void* sqlite3_value_text16le(value)"
114
- extern "const void* sqlite3_value_text16be(value)"
115
- extern "int sqlite3_value_type(value)"
116
-
117
- extern "void *sqlite3_aggregate_context(context,int)"
118
- extern "void *sqlite3_user_data(context)"
119
- extern "void *sqlite3_get_auxdata(context,int)"
120
- extern "void sqlite3_set_auxdata(context,int,void*,void*)"
121
-
122
- extern "void sqlite3_result_blob(context,const void*,int,void*)"
123
- extern "void sqlite3_result_double(context,double)"
124
- extern "void sqlite3_result_error(context,const char*,int)"
125
- extern "void sqlite3_result_error16(context,const void*,int)"
126
- extern "void sqlite3_result_int(context,int)"
127
- extern "void sqlite3_result_int64(context,int64)"
128
- extern "void sqlite3_result_null(context)"
129
- extern "void sqlite3_result_text(context,const char*,int,void*)"
130
- extern "void sqlite3_result_text16(context,const void*,int,void*)"
131
- extern "void sqlite3_result_text16le(context,const void*,int,void*)"
132
- extern "void sqlite3_result_text16be(context,const void*,int,void*)"
133
- extern "void sqlite3_result_value(context,value)"
134
-
135
- extern "int sqlite3_create_collation(db,const char*,int,void*,void*)"
136
- extern "int sqlite3_create_collation16(db,const char*,int,void*,void*)"
137
- extern "int sqlite3_collation_needed(db,void*,void*)"
138
- extern "int sqlite3_collation_needed16(db,void*,void*)"
139
-
140
- # ==== CRYPTO (NOT IN PUBLIC RELEASE) ====
141
- if defined?( CRYPTO_API ) && CRYPTO_API
142
- extern "int sqlite3_key(db,void*,int)"
143
- extern "int sqlite3_rekey(db,void*,int)"
144
- end
145
-
146
- # ==== EXPERIMENTAL ====
147
- if defined?( EXPERIMENTAL_API ) && EXPERIMENTAL_API
148
- extern "int sqlite3_progress_handler(db,int,void*,void*)"
149
- extern "int sqlite3_commit_hook(db,void*,void*)"
150
- end
151
-
152
- end
153
-
154
- end ; end ; end
@@ -1,307 +0,0 @@
1
- require 'sqlite3/driver/dl/api'
2
-
3
- warn "The DL driver for sqlite3-ruby is deprecated and will be removed"
4
- warn "in a future release. Please update your installation to use the"
5
- warn "Native driver."
6
-
7
- module Kernel
8
- # Allows arbitrary objects to be passed as a pointer to functions.
9
- # (Probably not very GC safe, but by encapsulating it like this we
10
- # can change the implementation later.)
11
- def to_ptr
12
- ptr = DL.malloc(DL.sizeof("L"))
13
- ptr.set_object self
14
- ptr
15
- end
16
- end
17
-
18
- class DL::PtrData
19
- # The inverse of the Kernel#to_ptr operation.
20
- def to_object
21
- n = to_s(4).unpack("L").first
22
- return nil if n < 1
23
- ObjectSpace._id2ref(n) rescue self.to_s
24
- end
25
-
26
- def set_object(obj)
27
- self[0] = [obj.object_id].pack("L")
28
- end
29
- end
30
-
31
- module SQLite3 ; module Driver ; module DL
32
-
33
- class Driver
34
- STATIC = ::DL::PtrData.new(0)
35
- TRANSIENT = ::DL::PtrData.new(-1)
36
-
37
- def open( filename, utf16=false )
38
- handle = ::DL::PtrData.new(0)
39
- result = API.send( ( utf16 ? :sqlite3_open16 : :sqlite3_open ),
40
- filename+"\0", handle.ref )
41
- [ result, handle ]
42
- end
43
-
44
- def errmsg( db, utf16=false )
45
- if utf16
46
- msg = API.sqlite3_errmsg16( db )
47
- msg.free = nil
48
- msg.to_s(utf16_length(msg))
49
- else
50
- API.sqlite3_errmsg( db )
51
- end
52
- end
53
-
54
- def prepare( db, sql, utf16=false )
55
- handle = ::DL::PtrData.new(0)
56
- remainder = ::DL::PtrData.new(0)
57
-
58
- result = API.send( ( utf16 ? :sqlite3_prepare16 : :sqlite3_prepare ),
59
- db, sql+"\0", sql.length, handle.ref, remainder.ref )
60
-
61
- args = utf16 ? [ utf16_length(remainder) ] : []
62
- remainder = remainder.to_s( *args )
63
-
64
- [ result, handle, remainder ]
65
- end
66
-
67
- def complete?( sql, utf16=false )
68
- API.send( utf16 ? :sqlite3_complete16 : :sqlite3_complete, sql+"\0" )
69
- end
70
-
71
- def value_blob( value )
72
- blob = API.sqlite3_value_blob( value )
73
- blob.free = nil
74
- blob.to_s( API.sqlite3_value_bytes( value ) )
75
- end
76
-
77
- def value_text( value, utf16=false )
78
- method = case utf16
79
- when nil, false then :sqlite3_value_text
80
- when :le then :sqlite3_value_text16le
81
- when :be then :sqlite3_value_text16be
82
- else :sqlite3_value_text16
83
- end
84
-
85
- result = API.send( method, value )
86
- if utf16
87
- result.free = nil
88
- size = API.sqlite3_value_bytes( value )
89
- result = result.to_s( size )
90
- end
91
-
92
- result
93
- end
94
-
95
- def column_blob( stmt, column )
96
- blob = API.sqlite3_column_blob( stmt, column )
97
- blob.free = nil
98
- blob.to_s( API.sqlite3_column_bytes( stmt, column ) )
99
- end
100
-
101
- def result_text( func, text, utf16=false )
102
- method = case utf16
103
- when false, nil then :sqlite3_result_text
104
- when :le then :sqlite3_result_text16le
105
- when :be then :sqlite3_result_text16be
106
- else :sqlite3_result_text16
107
- end
108
-
109
- s = text.to_s
110
- API.send( method, func, s, s.length, TRANSIENT )
111
- end
112
-
113
- def busy_handler( db, data=nil, &block )
114
- @busy_handler = block
115
-
116
- unless @busy_handler_callback
117
- @busy_handler_callback = ::DL.callback( "IPI" ) do |cookie, timeout|
118
- @busy_handler.call( cookie, timeout ) || 0
119
- end
120
- end
121
-
122
- API.sqlite3_busy_handler( db, block&&@busy_handler_callback, data )
123
- end
124
-
125
- def set_authorizer( db, data=nil, &block )
126
- @authorizer_handler = block
127
-
128
- unless @authorizer_handler_callback
129
- @authorizer_handler_callback = ::DL.callback( "IPIPPPP"
130
- ) do |cookie,mode,a,b,c,d|
131
- @authorizer_handler.call( cookie, mode,
132
- a&&a.to_s, b&&b.to_s, c&&c.to_s, d&&d.to_s ) || 0
133
- end
134
- end
135
-
136
- API.sqlite3_set_authorizer( db, block&&@authorizer_handler_callback,
137
- data )
138
- end
139
-
140
- def trace( db, data=nil, &block )
141
- @trace_handler = block
142
-
143
- unless @trace_handler_callback
144
- @trace_handler_callback = ::DL.callback( "IPS" ) do |cookie,sql|
145
- @trace_handler.call( cookie ? cookie.to_object : nil, sql ) || 0
146
- end
147
- end
148
-
149
- API.sqlite3_trace( db, block&&@trace_handler_callback, data )
150
- end
151
-
152
- def create_function( db, name, args, text, cookie,
153
- func, step, final )
154
- # begin
155
- if @func_handler_callback.nil? && func
156
- @func_handler_callback = ::DL.callback( "0PIP" ) do |context,nargs,args|
157
- args = args.to_s(nargs*4).unpack("L*").map {|i| ::DL::PtrData.new(i)}
158
- data = API.sqlite3_user_data( context ).to_object
159
- data[:func].call( context, *args )
160
- end
161
- end
162
-
163
- if @step_handler_callback.nil? && step
164
- @step_handler_callback = ::DL.callback( "0PIP" ) do |context,nargs,args|
165
- args = args.to_s(nargs*4).unpack("L*").map {|i| ::DL::PtrData.new(i)}
166
- data = API.sqlite3_user_data( context ).to_object
167
- data[:step].call( context, *args )
168
- end
169
- end
170
-
171
- if @final_handler_callback.nil? && final
172
- @final_handler_callback = ::DL.callback( "0P" ) do |context|
173
- data = API.sqlite3_user_data( context ).to_object
174
- data[:final].call( context )
175
- end
176
- end
177
-
178
- data = { :cookie => cookie,
179
- :name => name,
180
- :func => func,
181
- :step => step,
182
- :final => final }
183
-
184
- API.sqlite3_create_function( db, name, args, text, data,
185
- ( func ? @func_handler_callback : nil ),
186
- ( step ? @step_handler_callback : nil ),
187
- ( final ? @final_handler_callback : nil ) )
188
- end
189
-
190
- def aggregate_context( context )
191
- ptr = API.sqlite3_aggregate_context( context, 4 )
192
- ptr.free = nil
193
- obj = ( ptr ? ptr.to_object : nil )
194
- if obj.nil?
195
- obj = Hash.new
196
- ptr.set_object obj
197
- end
198
- obj
199
- end
200
-
201
- def bind_blob( stmt, index, value )
202
- s = value.to_s
203
- API.sqlite3_bind_blob( stmt, index, s, s.length, TRANSIENT )
204
- end
205
-
206
- def bind_text( stmt, index, value, utf16=false )
207
- s = value.to_s
208
- method = ( utf16 ? :sqlite3_bind_text16 : :sqlite3_bind_text )
209
- API.send( method, stmt, index, s, s.length, TRANSIENT )
210
- end
211
-
212
- def column_text( stmt, column )
213
- result = API.sqlite3_column_text( stmt, column )
214
- result ? result.to_s : nil
215
- end
216
-
217
- def column_name( stmt, column )
218
- result = API.sqlite3_column_name( stmt, column )
219
- result ? result.to_s : nil
220
- end
221
-
222
- def column_decltype( stmt, column )
223
- result = API.sqlite3_column_decltype( stmt, column )
224
- result ? result.to_s : nil
225
- end
226
-
227
- def self.api_delegate( name )
228
- define_method( name ) { |*args| API.send( "sqlite3_#{name}", *args ) }
229
- end
230
-
231
- api_delegate :aggregate_count
232
- api_delegate :bind_double
233
- api_delegate :bind_int
234
- api_delegate :bind_int64
235
- api_delegate :bind_null
236
- api_delegate :bind_parameter_index
237
- api_delegate :bind_parameter_name
238
- api_delegate :busy_timeout
239
- api_delegate :changes
240
- api_delegate :close
241
- api_delegate :column_bytes
242
- api_delegate :column_bytes16
243
- api_delegate :column_count
244
- api_delegate :column_double
245
- api_delegate :column_int
246
- api_delegate :column_int64
247
- api_delegate :column_type
248
- api_delegate :data_count
249
- api_delegate :errcode
250
- api_delegate :finalize
251
- api_delegate :interrupt
252
- api_delegate :last_insert_rowid
253
- api_delegate :libversion
254
- api_delegate :reset
255
- api_delegate :result_error
256
- api_delegate :step
257
- api_delegate :total_changes
258
- api_delegate :value_bytes
259
- api_delegate :value_bytes16
260
- api_delegate :value_double
261
- api_delegate :value_int
262
- api_delegate :value_int64
263
- api_delegate :value_type
264
-
265
- # ==== EXPERIMENTAL ====
266
- if defined?( EXPERIMENTAL_API ) && EXPERIMENTAL_API
267
- def progress_handler( db, n, data=nil, &block )
268
- @progress_handler = block
269
-
270
- unless @progress_handler_callback
271
- @progress_handler_callback = ::DL.callback( "IP" ) do |cookie|
272
- @progress_handler.call( cookie )
273
- end
274
- end
275
-
276
- API.sqlite3_progress_handler( db, n, block&&@progress_handler_callback,
277
- data )
278
- end
279
-
280
- def commit_hook( db, data=nil, &block )
281
- @commit_hook_handler = block
282
-
283
- unless @commit_hook_handler_callback
284
- @commit_hook_handler_callback = ::DL.callback( "IP" ) do |cookie|
285
- @commit_hook_handler.call( cookie )
286
- end
287
- end
288
-
289
- API.sqlite3_commit_hook( db, block&&@commit_hook_handler_callback,
290
- data )
291
- end
292
- end
293
-
294
- private
295
-
296
- def utf16_length(ptr)
297
- len = 0
298
- loop do
299
- break if ptr[len,1] == "\0"
300
- len += 2
301
- end
302
- len
303
- end
304
-
305
- end
306
-
307
- end ; end ; end