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

Instance Method Summary collapse

Instance Method Details

#auto_vacuumObject



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

def auto_vacuum
  get_boolean_pragma "auto_vacuum"
end

#auto_vacuum=(mode) ⇒ Object



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

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

#cache_sizeObject



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

def cache_size
  get_int_pragma "cache_size"
end

#cache_size=(size) ⇒ Object



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

def cache_size=(size)
  set_int_pragma "cache_size", size
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_sizeObject



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

def default_cache_size
  get_int_pragma "default_cache_size"
end

#default_cache_size=(size) ⇒ Object



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

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

#default_synchronousObject



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

def default_synchronous
  get_enum_pragma "default_synchronous"
end

#default_synchronous=(mode) ⇒ Object



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

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

#default_temp_storeObject



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

def default_temp_store
  get_enum_pragma "default_temp_store"
end

#default_temp_store=(mode) ⇒ Object



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

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

#foreign_key_list(table, &block) ⇒ Object

:yields: row



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

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

#full_column_namesObject



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

def full_column_names
  get_boolean_pragma "full_column_names"
end

#full_column_names=(mode) ⇒ Object



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

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

#index_info(index, &block) ⇒ Object

:yields: row



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

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

#index_list(table, &block) ⇒ Object

:yields: row



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

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

#integrity_checkObject

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



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

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

#parser_traceObject



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

def parser_trace
  get_boolean_pragma "parser_trace"
end

#parser_trace=(mode) ⇒ Object



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

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


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

def schema_cookie
  get_int_pragma "schema_cookie"
end

#schema_cookie=(cookie) ⇒ Object



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

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

#synchronousObject



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

def synchronous
  get_enum_pragma "synchronous"
end

#synchronous=(mode) ⇒ Object



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

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

#table_info(table, &block) ⇒ Object

:yields: row



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/sqlite3/pragmas.rb', line 217

def table_info(table, &block) # :yields: row
  columns, *rows = execute2("PRAGMA table_info(#{table})")

  needs_tweak_default = version_compare(driver.libversion, "3.3.7") > 0

  result = [] unless block_given?
  rows.each do |row|
    new_row = {}
    columns.each_with_index do |name, index|
      new_row[name] = row[index]
    end

    tweak_default(new_row) if needs_tweak_default

    if block_given?
      yield new_row
    else
      result << new_row
    end
  end

  result
end

#temp_storeObject



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

def temp_store
  get_enum_pragma "temp_store"
end

#temp_store=(mode) ⇒ Object



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

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


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

def user_cookie
  get_int_pragma "user_cookie"
end

#user_cookie=(cookie) ⇒ Object



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

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

#vdbe_traceObject



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

def vdbe_trace
  get_boolean_pragma "vdbe_trace"
end

#vdbe_trace=(mode) ⇒ Object



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

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