Module: SQLite3::Pragmas
- Included in:
- Database
- Defined in:
- lib/sqlite3/pragmas.rb
Overview
This module is intended for inclusion solely by the Database class. It defines convenience methods for the various pragmas supported by SQLite3.
For a detailed description of these pragmas, see the SQLite3 documentation at sqlite.org/pragma.html.
Constant Summary collapse
- SYNCHRONOUS_MODES =
The enumeration of valid synchronous modes.
[ [ 'full', 2 ], [ 'normal', 1 ], [ 'off', 0 ] ]
- TEMP_STORE_MODES =
The enumeration of valid temp store modes.
[ [ 'default', 0 ], [ 'file', 1 ], [ 'memory', 2 ] ]
- AUTO_VACUUM_MODES =
The enumeration of valid auto vacuum modes.
[ [ 'none', 0 ], [ 'full', 1 ], [ 'incremental', 2 ] ]
- JOURNAL_MODES =
The list of valid journaling modes.
[ [ 'delete' ], [ 'truncate' ], [ 'persist' ], [ 'memory' ], [ 'wal' ], [ 'off' ] ]
- LOCKING_MODES =
The list of valid locking modes.
[ [ 'normal' ], [ 'exclusive' ] ]
- ENCODINGS =
The list of valid encodings.
[ [ 'utf-8' ], [ 'utf-16' ], [ 'utf-16le' ], [ 'utf-16be ' ] ]
- WAL_CHECKPOINTS =
The list of valid WAL checkpoints.
[ [ 'passive' ], [ 'full' ], [ 'restart' ], [ 'truncate' ] ]
Instance Method Summary collapse
- #application_id ⇒ Object
- #application_id=(integer) ⇒ Object
- #auto_vacuum ⇒ Object
- #auto_vacuum=(mode) ⇒ Object
- #automatic_index ⇒ Object
- #automatic_index=(mode) ⇒ Object
- #busy_timeout ⇒ Object
- #busy_timeout=(milliseconds) ⇒ Object
- #cache_size ⇒ Object
- #cache_size=(size) ⇒ Object
- #cache_spill ⇒ Object
- #cache_spill=(mode) ⇒ Object
- #case_sensitive_like=(mode) ⇒ Object
- #cell_size_check ⇒ Object
- #cell_size_check=(mode) ⇒ Object
- #checkpoint_fullfsync ⇒ Object
- #checkpoint_fullfsync=(mode) ⇒ Object
-
#collation_list(&block) ⇒ Object
:yields: row.
-
#compile_options(&block) ⇒ Object
:yields: row.
- #count_changes ⇒ Object
- #count_changes=(mode) ⇒ Object
- #data_version ⇒ Object
-
#database_list(&block) ⇒ Object
:yields: row.
- #default_cache_size ⇒ Object
- #default_cache_size=(size) ⇒ Object
- #default_synchronous ⇒ Object
- #default_synchronous=(mode) ⇒ Object
- #default_temp_store ⇒ Object
- #default_temp_store=(mode) ⇒ Object
- #defer_foreign_keys ⇒ Object
- #defer_foreign_keys=(mode) ⇒ Object
- #encoding ⇒ Object
- #encoding=(mode) ⇒ Object
-
#foreign_key_check(*table, &block) ⇒ Object
:yields: row.
-
#foreign_key_list(table, &block) ⇒ Object
:yields: row.
- #foreign_keys ⇒ Object
- #foreign_keys=(mode) ⇒ Object
- #freelist_count ⇒ Object
- #full_column_names ⇒ Object
- #full_column_names=(mode) ⇒ Object
- #fullfsync ⇒ Object
- #fullfsync=(mode) ⇒ Object
-
#get_boolean_pragma(name) ⇒ Object
Returns
true
orfalse
depending on the value of the named pragma. -
#get_enum_pragma(name) ⇒ Object
Return the value of the given pragma.
-
#get_int_pragma(name) ⇒ Object
Returns the value of the given pragma as an integer.
-
#get_query_pragma(name, *parms, &block) ⇒ Object
Requests the given pragma (and parameters), and if the block is given, each row of the result set will be yielded to it.
- #ignore_check_constraints=(mode) ⇒ Object
-
#incremental_vacuum(pages, &block) ⇒ Object
:yields: row.
-
#index_info(index, &block) ⇒ Object
:yields: row.
-
#index_list(table, &block) ⇒ Object
:yields: row.
-
#index_xinfo(index, &block) ⇒ Object
:yields: row.
-
#integrity_check(*num_errors, &block) ⇒ Object
:yields: row.
- #journal_mode ⇒ Object
- #journal_mode=(mode) ⇒ Object
- #journal_size_limit ⇒ Object
- #journal_size_limit=(size) ⇒ Object
- #legacy_file_format ⇒ Object
- #legacy_file_format=(mode) ⇒ Object
- #locking_mode ⇒ Object
- #locking_mode=(mode) ⇒ Object
- #max_page_count ⇒ Object
- #max_page_count=(size) ⇒ Object
- #mmap_size ⇒ Object
- #mmap_size=(size) ⇒ Object
- #page_count ⇒ Object
- #page_size ⇒ Object
- #page_size=(size) ⇒ Object
- #parser_trace=(mode) ⇒ Object
- #query_only ⇒ Object
- #query_only=(mode) ⇒ Object
-
#quick_check(*num_errors, &block) ⇒ Object
:yields: row.
- #read_uncommitted ⇒ Object
- #read_uncommitted=(mode) ⇒ Object
- #recursive_triggers ⇒ Object
- #recursive_triggers=(mode) ⇒ Object
- #reverse_unordered_selects ⇒ Object
- #reverse_unordered_selects=(mode) ⇒ Object
- #schema_cookie ⇒ Object
- #schema_cookie=(cookie) ⇒ Object
- #schema_version ⇒ Object
- #schema_version=(version) ⇒ Object
- #secure_delete ⇒ Object
- #secure_delete=(mode) ⇒ Object
-
#set_boolean_pragma(name, mode) ⇒ Object
Sets the given pragma to the given boolean value.
-
#set_enum_pragma(name, mode, enums) ⇒ Object
Set the value of the given pragma to
mode
. -
#set_int_pragma(name, value) ⇒ Object
Set the value of the given pragma to the integer value of the
value
parameter. - #short_column_names ⇒ Object
- #short_column_names=(mode) ⇒ Object
- #shrink_memory ⇒ Object
- #soft_heap_limit ⇒ Object
- #soft_heap_limit=(mode) ⇒ Object
-
#stats(&block) ⇒ Object
:yields: row.
- #synchronous ⇒ Object
- #synchronous=(mode) ⇒ Object
-
#table_info(table) ⇒ Object
Returns information about
table
. - #temp_store ⇒ Object
- #temp_store=(mode) ⇒ Object
- #threads ⇒ Object
- #threads=(count) ⇒ Object
- #user_cookie ⇒ Object
- #user_cookie=(cookie) ⇒ Object
- #user_version ⇒ Object
- #user_version=(version) ⇒ Object
- #vdbe_addoptrace=(mode) ⇒ Object
- #vdbe_debug=(mode) ⇒ Object
- #vdbe_listing=(mode) ⇒ Object
- #vdbe_trace ⇒ Object
- #vdbe_trace=(mode) ⇒ Object
- #wal_autocheckpoint ⇒ Object
- #wal_autocheckpoint=(mode) ⇒ Object
- #wal_checkpoint ⇒ Object
- #wal_checkpoint=(mode) ⇒ Object
- #writable_schema=(mode) ⇒ Object
Instance Method Details
#application_id ⇒ Object
113 114 115 |
# File 'lib/sqlite3/pragmas.rb', line 113 def application_id get_int_pragma "application_id" end |
#application_id=(integer) ⇒ Object
117 118 119 |
# File 'lib/sqlite3/pragmas.rb', line 117 def application_id=( integer ) set_int_pragma "application_id", integer end |
#auto_vacuum ⇒ Object
121 122 123 |
# File 'lib/sqlite3/pragmas.rb', line 121 def auto_vacuum get_enum_pragma "auto_vacuum" end |
#auto_vacuum=(mode) ⇒ Object
125 126 127 |
# File 'lib/sqlite3/pragmas.rb', line 125 def auto_vacuum=( mode ) set_enum_pragma "auto_vacuum", mode, AUTO_VACUUM_MODES end |
#automatic_index ⇒ Object
129 130 131 |
# File 'lib/sqlite3/pragmas.rb', line 129 def automatic_index get_boolean_pragma "automatic_index" end |
#automatic_index=(mode) ⇒ Object
133 134 135 |
# File 'lib/sqlite3/pragmas.rb', line 133 def automatic_index=( mode ) set_boolean_pragma "automatic_index", mode end |
#busy_timeout ⇒ Object
137 138 139 |
# File 'lib/sqlite3/pragmas.rb', line 137 def busy_timeout get_int_pragma "busy_timeout" end |
#busy_timeout=(milliseconds) ⇒ Object
141 142 143 |
# File 'lib/sqlite3/pragmas.rb', line 141 def busy_timeout=( milliseconds ) set_int_pragma "busy_timeout", milliseconds end |
#cache_size ⇒ Object
145 146 147 |
# File 'lib/sqlite3/pragmas.rb', line 145 def cache_size get_int_pragma "cache_size" end |
#cache_size=(size) ⇒ Object
149 150 151 |
# File 'lib/sqlite3/pragmas.rb', line 149 def cache_size=( size ) set_int_pragma "cache_size", size end |
#cache_spill ⇒ Object
153 154 155 |
# File 'lib/sqlite3/pragmas.rb', line 153 def cache_spill get_boolean_pragma "cache_spill" end |
#cache_spill=(mode) ⇒ Object
157 158 159 |
# File 'lib/sqlite3/pragmas.rb', line 157 def cache_spill=( mode ) set_boolean_pragma "cache_spill", mode end |
#case_sensitive_like=(mode) ⇒ Object
161 162 163 |
# File 'lib/sqlite3/pragmas.rb', line 161 def case_sensitive_like=( mode ) set_boolean_pragma "case_sensitive_like", mode end |
#cell_size_check ⇒ Object
165 166 167 |
# File 'lib/sqlite3/pragmas.rb', line 165 def cell_size_check get_boolean_pragma "cell_size_check" end |
#cell_size_check=(mode) ⇒ Object
169 170 171 |
# File 'lib/sqlite3/pragmas.rb', line 169 def cell_size_check=( mode ) set_boolean_pragma "cell_size_check", mode end |
#checkpoint_fullfsync ⇒ Object
173 174 175 |
# File 'lib/sqlite3/pragmas.rb', line 173 def checkpoint_fullfsync get_boolean_pragma "checkpoint_fullfsync" end |
#checkpoint_fullfsync=(mode) ⇒ Object
177 178 179 |
# File 'lib/sqlite3/pragmas.rb', line 177 def checkpoint_fullfsync=( mode ) set_boolean_pragma "checkpoint_fullfsync", mode end |
#collation_list(&block) ⇒ Object
:yields: row
181 182 183 |
# File 'lib/sqlite3/pragmas.rb', line 181 def collation_list( &block ) # :yields: row get_query_pragma "collation_list", &block end |
#compile_options(&block) ⇒ Object
:yields: row
185 186 187 |
# File 'lib/sqlite3/pragmas.rb', line 185 def ( &block ) # :yields: row get_query_pragma "compile_options", &block end |
#count_changes ⇒ Object
189 190 191 |
# File 'lib/sqlite3/pragmas.rb', line 189 def count_changes get_boolean_pragma "count_changes" end |
#count_changes=(mode) ⇒ Object
193 194 195 |
# File 'lib/sqlite3/pragmas.rb', line 193 def count_changes=( mode ) set_boolean_pragma "count_changes", mode end |
#data_version ⇒ Object
197 198 199 |
# File 'lib/sqlite3/pragmas.rb', line 197 def data_version get_int_pragma "data_version" end |
#database_list(&block) ⇒ Object
:yields: row
201 202 203 |
# File 'lib/sqlite3/pragmas.rb', line 201 def database_list( &block ) # :yields: row get_query_pragma "database_list", &block end |
#default_cache_size ⇒ Object
205 206 207 |
# File 'lib/sqlite3/pragmas.rb', line 205 def default_cache_size get_int_pragma "default_cache_size" end |
#default_cache_size=(size) ⇒ Object
209 210 211 |
# File 'lib/sqlite3/pragmas.rb', line 209 def default_cache_size=( size ) set_int_pragma "default_cache_size", size end |
#default_synchronous ⇒ Object
213 214 215 |
# File 'lib/sqlite3/pragmas.rb', line 213 def default_synchronous get_enum_pragma "default_synchronous" end |
#default_synchronous=(mode) ⇒ Object
217 218 219 |
# File 'lib/sqlite3/pragmas.rb', line 217 def default_synchronous=( mode ) set_enum_pragma "default_synchronous", mode, SYNCHRONOUS_MODES end |
#default_temp_store ⇒ Object
221 222 223 |
# File 'lib/sqlite3/pragmas.rb', line 221 def default_temp_store get_enum_pragma "default_temp_store" end |
#default_temp_store=(mode) ⇒ Object
225 226 227 |
# File 'lib/sqlite3/pragmas.rb', line 225 def default_temp_store=( mode ) set_enum_pragma "default_temp_store", mode, TEMP_STORE_MODES end |
#defer_foreign_keys ⇒ Object
229 230 231 |
# File 'lib/sqlite3/pragmas.rb', line 229 def defer_foreign_keys get_boolean_pragma "defer_foreign_keys" end |
#defer_foreign_keys=(mode) ⇒ Object
233 234 235 |
# File 'lib/sqlite3/pragmas.rb', line 233 def defer_foreign_keys=( mode ) set_boolean_pragma "defer_foreign_keys", mode end |
#encoding ⇒ Object
237 238 239 |
# File 'lib/sqlite3/pragmas.rb', line 237 def encoding get_enum_pragma "encoding" end |
#encoding=(mode) ⇒ Object
241 242 243 |
# File 'lib/sqlite3/pragmas.rb', line 241 def encoding=( mode ) set_enum_pragma "encoding", mode, ENCODINGS end |
#foreign_key_check(*table, &block) ⇒ Object
:yields: row
245 246 247 |
# File 'lib/sqlite3/pragmas.rb', line 245 def foreign_key_check( *table, &block ) # :yields: row get_query_pragma "foreign_key_check", *table, &block end |
#foreign_key_list(table, &block) ⇒ Object
:yields: row
249 250 251 |
# File 'lib/sqlite3/pragmas.rb', line 249 def foreign_key_list( table, &block ) # :yields: row get_query_pragma "foreign_key_list", table, &block end |
#foreign_keys ⇒ Object
253 254 255 |
# File 'lib/sqlite3/pragmas.rb', line 253 def foreign_keys get_boolean_pragma "foreign_keys" end |
#foreign_keys=(mode) ⇒ Object
257 258 259 |
# File 'lib/sqlite3/pragmas.rb', line 257 def foreign_keys=( mode ) set_boolean_pragma "foreign_keys", mode end |
#freelist_count ⇒ Object
261 262 263 |
# File 'lib/sqlite3/pragmas.rb', line 261 def freelist_count get_int_pragma "freelist_count" end |
#full_column_names ⇒ Object
265 266 267 |
# File 'lib/sqlite3/pragmas.rb', line 265 def full_column_names get_boolean_pragma "full_column_names" end |
#full_column_names=(mode) ⇒ Object
269 270 271 |
# File 'lib/sqlite3/pragmas.rb', line 269 def full_column_names=( mode ) set_boolean_pragma "full_column_names", mode end |
#fullfsync ⇒ Object
273 274 275 |
# File 'lib/sqlite3/pragmas.rb', line 273 def fullfsync get_boolean_pragma "fullfsync" end |
#fullfsync=(mode) ⇒ Object
277 278 279 |
# File 'lib/sqlite3/pragmas.rb', line 277 def fullfsync=( mode ) set_boolean_pragma "fullfsync", mode end |
#get_boolean_pragma(name) ⇒ Object
Returns true
or false
depending on the value of the named pragma.
13 14 15 |
# File 'lib/sqlite3/pragmas.rb', line 13 def get_boolean_pragma( name ) get_first_value( "PRAGMA #{name}" ) != "0" end |
#get_enum_pragma(name) ⇒ Object
Return the value of the given pragma.
55 56 57 |
# File 'lib/sqlite3/pragmas.rb', line 55 def get_enum_pragma( name ) get_first_value( "PRAGMA #{name}" ) end |
#get_int_pragma(name) ⇒ Object
Returns the value of the given pragma as an integer.
72 73 74 |
# File 'lib/sqlite3/pragmas.rb', line 72 def get_int_pragma( name ) get_first_value( "PRAGMA #{name}" ).to_i end |
#get_query_pragma(name, *parms, &block) ⇒ Object
Requests the given pragma (and parameters), and if the block is given, each row of the result set will be yielded to it. Otherwise, the results are returned as an array.
45 46 47 48 49 50 51 52 |
# File 'lib/sqlite3/pragmas.rb', line 45 def get_query_pragma( name, *parms, &block ) # :yields: row if parms.empty? execute( "PRAGMA #{name}", &block ) else args = "'" + parms.join("','") + "'" execute( "PRAGMA #{name}( #{args} )", &block ) end end |
#ignore_check_constraints=(mode) ⇒ Object
281 282 283 |
# File 'lib/sqlite3/pragmas.rb', line 281 def ignore_check_constraints=( mode ) set_boolean_pragma "ignore_check_constraints", mode end |
#incremental_vacuum(pages, &block) ⇒ Object
:yields: row
285 286 287 |
# File 'lib/sqlite3/pragmas.rb', line 285 def incremental_vacuum( pages, &block ) # :yields: row get_query_pragma "incremental_vacuum", pages, &block end |
#index_info(index, &block) ⇒ Object
:yields: row
289 290 291 |
# File 'lib/sqlite3/pragmas.rb', line 289 def index_info( index, &block ) # :yields: row get_query_pragma "index_info", index, &block end |
#index_list(table, &block) ⇒ Object
:yields: row
293 294 295 |
# File 'lib/sqlite3/pragmas.rb', line 293 def index_list( table, &block ) # :yields: row get_query_pragma "index_list", table, &block end |
#index_xinfo(index, &block) ⇒ Object
:yields: row
297 298 299 |
# File 'lib/sqlite3/pragmas.rb', line 297 def index_xinfo( index, &block ) # :yields: row get_query_pragma "index_xinfo", index, &block end |
#integrity_check(*num_errors, &block) ⇒ Object
:yields: row
107 108 109 110 111 |
# File 'lib/sqlite3/pragmas.rb', line 107 def integrity_check execute( "PRAGMA integrity_check" ) do |row| raise Exception, row[0] if row[0] != "ok" end end |
#journal_mode ⇒ Object
305 306 307 |
# File 'lib/sqlite3/pragmas.rb', line 305 def journal_mode get_enum_pragma "journal_mode" end |
#journal_mode=(mode) ⇒ Object
309 310 311 |
# File 'lib/sqlite3/pragmas.rb', line 309 def journal_mode=( mode ) set_enum_pragma "journal_mode", mode, JOURNAL_MODES end |
#journal_size_limit ⇒ Object
313 314 315 |
# File 'lib/sqlite3/pragmas.rb', line 313 def journal_size_limit get_int_pragma "journal_size_limit" end |
#journal_size_limit=(size) ⇒ Object
317 318 319 |
# File 'lib/sqlite3/pragmas.rb', line 317 def journal_size_limit=( size ) set_int_pragma "journal_size_limit", size end |
#legacy_file_format ⇒ Object
321 322 323 |
# File 'lib/sqlite3/pragmas.rb', line 321 def legacy_file_format get_boolean_pragma "legacy_file_format" end |
#legacy_file_format=(mode) ⇒ Object
325 326 327 |
# File 'lib/sqlite3/pragmas.rb', line 325 def legacy_file_format=( mode ) set_boolean_pragma "legacy_file_format", mode end |
#locking_mode ⇒ Object
329 330 331 |
# File 'lib/sqlite3/pragmas.rb', line 329 def locking_mode get_enum_pragma "locking_mode" end |
#locking_mode=(mode) ⇒ Object
333 334 335 |
# File 'lib/sqlite3/pragmas.rb', line 333 def locking_mode=( mode ) set_enum_pragma "locking_mode", mode, LOCKING_MODES end |
#max_page_count ⇒ Object
337 338 339 |
# File 'lib/sqlite3/pragmas.rb', line 337 def max_page_count get_int_pragma "max_page_count" end |
#max_page_count=(size) ⇒ Object
341 342 343 |
# File 'lib/sqlite3/pragmas.rb', line 341 def max_page_count=( size ) set_int_pragma "max_page_count", size end |
#mmap_size ⇒ Object
345 346 347 |
# File 'lib/sqlite3/pragmas.rb', line 345 def mmap_size get_int_pragma "mmap_size" end |
#mmap_size=(size) ⇒ Object
349 350 351 |
# File 'lib/sqlite3/pragmas.rb', line 349 def mmap_size=( size ) set_int_pragma "mmap_size", size end |
#page_count ⇒ Object
353 354 355 |
# File 'lib/sqlite3/pragmas.rb', line 353 def page_count get_int_pragma "page_count" end |
#page_size ⇒ Object
357 358 359 |
# File 'lib/sqlite3/pragmas.rb', line 357 def page_size get_int_pragma "page_size" end |
#page_size=(size) ⇒ Object
361 362 363 |
# File 'lib/sqlite3/pragmas.rb', line 361 def page_size=( size ) set_int_pragma "page_size", size end |
#parser_trace=(mode) ⇒ Object
365 366 367 |
# File 'lib/sqlite3/pragmas.rb', line 365 def parser_trace=( mode ) set_boolean_pragma "parser_trace", mode end |
#query_only ⇒ Object
369 370 371 |
# File 'lib/sqlite3/pragmas.rb', line 369 def query_only get_boolean_pragma "query_only" end |
#query_only=(mode) ⇒ Object
373 374 375 |
# File 'lib/sqlite3/pragmas.rb', line 373 def query_only=( mode ) set_boolean_pragma "query_only", mode end |
#quick_check(*num_errors, &block) ⇒ Object
:yields: row
377 378 379 |
# File 'lib/sqlite3/pragmas.rb', line 377 def quick_check( *num_errors, &block ) # :yields: row get_query_pragma "quick_check", *num_errors, &block end |
#read_uncommitted ⇒ Object
381 382 383 |
# File 'lib/sqlite3/pragmas.rb', line 381 def read_uncommitted get_boolean_pragma "read_uncommitted" end |
#read_uncommitted=(mode) ⇒ Object
385 386 387 |
# File 'lib/sqlite3/pragmas.rb', line 385 def read_uncommitted=( mode ) set_boolean_pragma "read_uncommitted", mode end |
#recursive_triggers ⇒ Object
389 390 391 |
# File 'lib/sqlite3/pragmas.rb', line 389 def recursive_triggers get_boolean_pragma "recursive_triggers" end |
#recursive_triggers=(mode) ⇒ Object
393 394 395 |
# File 'lib/sqlite3/pragmas.rb', line 393 def recursive_triggers=( mode ) set_boolean_pragma "recursive_triggers", mode end |
#reverse_unordered_selects ⇒ Object
397 398 399 |
# File 'lib/sqlite3/pragmas.rb', line 397 def reverse_unordered_selects get_boolean_pragma "reverse_unordered_selects" end |
#reverse_unordered_selects=(mode) ⇒ Object
401 402 403 |
# File 'lib/sqlite3/pragmas.rb', line 401 def reverse_unordered_selects=( mode ) set_boolean_pragma "reverse_unordered_selects", mode end |
#schema_cookie ⇒ Object
405 406 407 |
# File 'lib/sqlite3/pragmas.rb', line 405 def get_int_pragma "schema_cookie" end |
#schema_cookie=(cookie) ⇒ Object
409 410 411 |
# File 'lib/sqlite3/pragmas.rb', line 409 def ( ) set_int_pragma "schema_cookie", end |
#schema_version ⇒ Object
413 414 415 |
# File 'lib/sqlite3/pragmas.rb', line 413 def schema_version get_int_pragma "schema_version" end |
#schema_version=(version) ⇒ Object
417 418 419 |
# File 'lib/sqlite3/pragmas.rb', line 417 def schema_version=( version ) set_int_pragma "schema_version", version end |
#secure_delete ⇒ Object
421 422 423 |
# File 'lib/sqlite3/pragmas.rb', line 421 def secure_delete get_boolean_pragma "secure_delete" end |
#secure_delete=(mode) ⇒ Object
425 426 427 |
# File 'lib/sqlite3/pragmas.rb', line 425 def secure_delete=( mode ) set_boolean_pragma "secure_delete", mode end |
#set_boolean_pragma(name, mode) ⇒ Object
Sets the given pragma to the given boolean value. The value itself may be true
or false
, or any other commonly used string or integer that represents truth.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sqlite3/pragmas.rb', line 20 def set_boolean_pragma( name, mode ) case mode when String case mode.downcase when "on", "yes", "true", "y", "t"; mode = "'ON'" when "off", "no", "false", "n", "f"; mode = "'OFF'" else raise Exception, "unrecognized pragma parameter #{mode.inspect}" end when true, 1 mode = "ON" when false, 0, nil mode = "OFF" else raise Exception, "unrecognized pragma parameter #{mode.inspect}" end execute( "PRAGMA #{name}=#{mode}" ) end |
#set_enum_pragma(name, mode, enums) ⇒ Object
Set the value of the given pragma to mode
. The mode
parameter must conform to one of the values in the given enum
array. Each entry in the array is another array comprised of elements in the enumeration that have duplicate values. See #synchronous, #default_synchronous, #temp_store, and #default_temp_store for usage examples.
64 65 66 67 68 69 |
# File 'lib/sqlite3/pragmas.rb', line 64 def set_enum_pragma( name, mode, enums ) match = enums.find { |p| p.find { |i| i.to_s.downcase == mode.to_s.downcase } } raise Exception, "unrecognized #{name} #{mode.inspect}" unless match execute( "PRAGMA #{name}='#{match.first.upcase}'" ) end |
#set_int_pragma(name, value) ⇒ Object
Set the value of the given pragma to the integer value of the value
parameter.
78 79 80 |
# File 'lib/sqlite3/pragmas.rb', line 78 def set_int_pragma( name, value ) execute( "PRAGMA #{name}=#{value.to_i}" ) end |
#short_column_names ⇒ Object
429 430 431 |
# File 'lib/sqlite3/pragmas.rb', line 429 def short_column_names get_boolean_pragma "short_column_names" end |
#short_column_names=(mode) ⇒ Object
433 434 435 |
# File 'lib/sqlite3/pragmas.rb', line 433 def short_column_names=( mode ) set_boolean_pragma "short_column_names", mode end |
#shrink_memory ⇒ Object
437 438 439 |
# File 'lib/sqlite3/pragmas.rb', line 437 def shrink_memory execute( "PRAGMA shrink_memory" ) end |
#soft_heap_limit ⇒ Object
441 442 443 |
# File 'lib/sqlite3/pragmas.rb', line 441 def soft_heap_limit get_int_pragma "soft_heap_limit" end |
#soft_heap_limit=(mode) ⇒ Object
445 446 447 |
# File 'lib/sqlite3/pragmas.rb', line 445 def soft_heap_limit=( mode ) set_int_pragma "soft_heap_limit", mode end |
#stats(&block) ⇒ Object
:yields: row
449 450 451 |
# File 'lib/sqlite3/pragmas.rb', line 449 def stats( &block ) # :yields: row get_query_pragma "stats", &block end |
#synchronous ⇒ Object
453 454 455 |
# File 'lib/sqlite3/pragmas.rb', line 453 def synchronous get_enum_pragma "synchronous" end |
#synchronous=(mode) ⇒ Object
457 458 459 |
# File 'lib/sqlite3/pragmas.rb', line 457 def synchronous=( mode ) set_enum_pragma "synchronous", mode, SYNCHRONOUS_MODES end |
#table_info(table) ⇒ Object
Returns information about table
. Yields each row of table information if a block is provided.
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/sqlite3/pragmas.rb', line 536 def table_info table stmt = prepare "PRAGMA table_info(#{table})" columns = stmt.columns needs_tweak_default = version_compare(SQLite3.libversion.to_s, "3.3.7") > 0 result = [] unless block_given? stmt.each do |row| new_row = Hash[columns.zip(row)] # FIXME: This should be removed but is required for older versions # of rails if(Object.const_defined?(:ActiveRecord)) new_row['notnull'] = new_row['notnull'].to_s end tweak_default(new_row) if needs_tweak_default if block_given? yield new_row else result << new_row end end stmt.close result end |
#temp_store ⇒ Object
461 462 463 |
# File 'lib/sqlite3/pragmas.rb', line 461 def temp_store get_enum_pragma "temp_store" end |
#temp_store=(mode) ⇒ Object
465 466 467 |
# File 'lib/sqlite3/pragmas.rb', line 465 def temp_store=( mode ) set_enum_pragma "temp_store", mode, TEMP_STORE_MODES end |
#threads ⇒ Object
469 470 471 |
# File 'lib/sqlite3/pragmas.rb', line 469 def threads get_int_pragma "threads" end |
#threads=(count) ⇒ Object
473 474 475 |
# File 'lib/sqlite3/pragmas.rb', line 473 def threads=( count ) set_int_pragma "threads", count end |
#user_cookie ⇒ Object
477 478 479 |
# File 'lib/sqlite3/pragmas.rb', line 477 def get_int_pragma "user_cookie" end |
#user_cookie=(cookie) ⇒ Object
481 482 483 |
# File 'lib/sqlite3/pragmas.rb', line 481 def ( ) set_int_pragma "user_cookie", end |
#user_version ⇒ Object
485 486 487 |
# File 'lib/sqlite3/pragmas.rb', line 485 def user_version get_int_pragma "user_version" end |
#user_version=(version) ⇒ Object
489 490 491 |
# File 'lib/sqlite3/pragmas.rb', line 489 def user_version=( version ) set_int_pragma "user_version", version end |
#vdbe_addoptrace=(mode) ⇒ Object
493 494 495 |
# File 'lib/sqlite3/pragmas.rb', line 493 def vdbe_addoptrace=( mode ) set_boolean_pragma "vdbe_addoptrace", mode end |
#vdbe_debug=(mode) ⇒ Object
497 498 499 |
# File 'lib/sqlite3/pragmas.rb', line 497 def vdbe_debug=( mode ) set_boolean_pragma "vdbe_debug", mode end |
#vdbe_listing=(mode) ⇒ Object
501 502 503 |
# File 'lib/sqlite3/pragmas.rb', line 501 def vdbe_listing=( mode ) set_boolean_pragma "vdbe_listing", mode end |
#vdbe_trace ⇒ Object
505 506 507 |
# File 'lib/sqlite3/pragmas.rb', line 505 def vdbe_trace get_boolean_pragma "vdbe_trace" end |
#vdbe_trace=(mode) ⇒ Object
509 510 511 |
# File 'lib/sqlite3/pragmas.rb', line 509 def vdbe_trace=( mode ) set_boolean_pragma "vdbe_trace", mode end |
#wal_autocheckpoint ⇒ Object
513 514 515 |
# File 'lib/sqlite3/pragmas.rb', line 513 def wal_autocheckpoint get_int_pragma "wal_autocheckpoint" end |
#wal_autocheckpoint=(mode) ⇒ Object
517 518 519 |
# File 'lib/sqlite3/pragmas.rb', line 517 def wal_autocheckpoint=( mode ) set_int_pragma "wal_autocheckpoint", mode end |
#wal_checkpoint ⇒ Object
521 522 523 |
# File 'lib/sqlite3/pragmas.rb', line 521 def wal_checkpoint get_enum_pragma "wal_checkpoint" end |
#wal_checkpoint=(mode) ⇒ Object
525 526 527 |
# File 'lib/sqlite3/pragmas.rb', line 525 def wal_checkpoint=( mode ) set_enum_pragma "wal_checkpoint", mode, WAL_CHECKPOINTS end |
#writable_schema=(mode) ⇒ Object
529 530 531 |
# File 'lib/sqlite3/pragmas.rb', line 529 def writable_schema=( mode ) set_boolean_pragma "writable_schema", mode end |