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

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 ] ]

Instance Method Summary (collapse)

Instance Method Details

- (Object) auto_vacuum



104
105
106
# File 'lib/sqlite3/pragmas.rb', line 104

def auto_vacuum
  get_boolean_pragma "auto_vacuum"
end

- (Object) auto_vacuum=(mode)



108
109
110
# File 'lib/sqlite3/pragmas.rb', line 108

def auto_vacuum=( mode )
  set_boolean_pragma "auto_vacuum", mode
end

- (Object) cache_size



128
129
130
# File 'lib/sqlite3/pragmas.rb', line 128

def cache_size
  get_int_pragma "cache_size"
end

- (Object) cache_size=(size)



132
133
134
# File 'lib/sqlite3/pragmas.rb', line 132

def cache_size=( size )
  set_int_pragma "cache_size", size
end

- (Object) database_list(&block)

:yields: row



200
201
202
# File 'lib/sqlite3/pragmas.rb', line 200

def database_list( &block ) # :yields: row
  get_query_pragma "database_list", &block
end

- (Object) default_cache_size



136
137
138
# File 'lib/sqlite3/pragmas.rb', line 136

def default_cache_size
  get_int_pragma "default_cache_size"
end

- (Object) default_cache_size=(size)



140
141
142
# File 'lib/sqlite3/pragmas.rb', line 140

def default_cache_size=( size )
  set_int_pragma "default_cache_size", size
end

- (Object) default_synchronous



144
145
146
# File 'lib/sqlite3/pragmas.rb', line 144

def default_synchronous
  get_enum_pragma "default_synchronous"
end

- (Object) default_synchronous=(mode)



148
149
150
# File 'lib/sqlite3/pragmas.rb', line 148

def default_synchronous=( mode )
  set_enum_pragma "default_synchronous", mode, SYNCHRONOUS_MODES
end

- (Object) default_temp_store



160
161
162
# File 'lib/sqlite3/pragmas.rb', line 160

def default_temp_store
  get_enum_pragma "default_temp_store"
end

- (Object) default_temp_store=(mode)



164
165
166
# File 'lib/sqlite3/pragmas.rb', line 164

def default_temp_store=( mode )
  set_enum_pragma "default_temp_store", mode, TEMP_STORE_MODES
end

- (Object) foreign_key_list(table, &block)

:yields: row



204
205
206
# File 'lib/sqlite3/pragmas.rb', line 204

def foreign_key_list( table, &block ) # :yields: row
  get_query_pragma "foreign_key_list", table, &block
end

- (Object) full_column_names



176
177
178
# File 'lib/sqlite3/pragmas.rb', line 176

def full_column_names
  get_boolean_pragma "full_column_names"
end

- (Object) full_column_names=(mode)



180
181
182
# File 'lib/sqlite3/pragmas.rb', line 180

def full_column_names=( mode )
  set_boolean_pragma "full_column_names", mode
end

- (Object) index_info(index, &block)

:yields: row



208
209
210
# File 'lib/sqlite3/pragmas.rb', line 208

def index_info( index, &block ) # :yields: row
  get_query_pragma "index_info", index, &block
end

- (Object) index_list(table, &block)

:yields: row



212
213
214
# File 'lib/sqlite3/pragmas.rb', line 212

def index_list( table, &block ) # :yields: row
  get_query_pragma "index_list", table, &block
end

- (Object) integrity_check

Does an integrity check on the database. If the check fails, a SQLite3::Exception will be raised. Otherwise it returns silently.



98
99
100
101
102
# File 'lib/sqlite3/pragmas.rb', line 98

def integrity_check
  execute( "PRAGMA integrity_check" ) do |row|
    raise Exception, row[0] if row[0] != "ok"
  end
end

- (Object) parser_trace



184
185
186
# File 'lib/sqlite3/pragmas.rb', line 184

def parser_trace
  get_boolean_pragma "parser_trace"
end

- (Object) parser_trace=(mode)



188
189
190
# File 'lib/sqlite3/pragmas.rb', line 188

def parser_trace=( mode )
  set_boolean_pragma "parser_trace", mode
end


112
113
114
# File 'lib/sqlite3/pragmas.rb', line 112

def schema_cookie
  get_int_pragma "schema_cookie"
end

- (Object) schema_cookie=(cookie)



116
117
118
# File 'lib/sqlite3/pragmas.rb', line 116

def schema_cookie=( cookie )
  set_int_pragma "schema_cookie", cookie
end

- (Object) synchronous



152
153
154
# File 'lib/sqlite3/pragmas.rb', line 152

def synchronous
  get_enum_pragma "synchronous"
end

- (Object) synchronous=(mode)



156
157
158
# File 'lib/sqlite3/pragmas.rb', line 156

def synchronous=( mode )
  set_enum_pragma "synchronous", mode, SYNCHRONOUS_MODES
end

- (Object) table_info(table)

Returns information about table. Yields each row of table information if a block is provided.



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/sqlite3/pragmas.rb', line 219

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

- (Object) temp_store



168
169
170
# File 'lib/sqlite3/pragmas.rb', line 168

def temp_store
  get_enum_pragma "temp_store"
end

- (Object) temp_store=(mode)



172
173
174
# File 'lib/sqlite3/pragmas.rb', line 172

def temp_store=( mode )
  set_enum_pragma "temp_store", mode, TEMP_STORE_MODES
end


120
121
122
# File 'lib/sqlite3/pragmas.rb', line 120

def user_cookie
  get_int_pragma "user_cookie"
end

- (Object) user_cookie=(cookie)



124
125
126
# File 'lib/sqlite3/pragmas.rb', line 124

def user_cookie=( cookie )
  set_int_pragma "user_cookie", cookie
end

- (Object) vdbe_trace



192
193
194
# File 'lib/sqlite3/pragmas.rb', line 192

def vdbe_trace
  get_boolean_pragma "vdbe_trace"
end

- (Object) vdbe_trace=(mode)



196
197
198
# File 'lib/sqlite3/pragmas.rb', line 196

def vdbe_trace=( mode )
  set_boolean_pragma "vdbe_trace", mode
end