Fix typos in session extension header comments. No changes to code.
[sqlite.git] / tool / mkpragmatab.tcl
blob1bfbeb7c58befc4e916a48e60f2e18b55d594bf2
1 #!/usr/bin/tclsh
3 # Run this script to generate the pragma name lookup table C code.
5 # To add new pragmas, first add the name and other relevant attributes
6 # of the pragma to the "pragma_def" object below. Then run this script
7 # to generate the ../src/pragma.h header file that contains macros and
8 # the lookup table needed for pragma name lookup in the pragma.c module.
9 # Then add the extra "case PragTyp_XXXXX:" and subsequent code for the
10 # new pragma in ../src/pragma.c.
13 # Flag meanings:
14 set flagMeaning(NeedSchema) {Force schema load before running}
15 set flagMeaning(ReadOnly) {Read-only HEADER_VALUE}
16 set flagMeaning(Result0) {Acts as query when no argument}
17 set flagMeaning(Result1) {Acts as query when has one argument}
18 set flagMeaning(SchemaReq) {Schema required - "main" is default}
19 set flagMeaning(SchemaOpt) {Schema restricts name search if present}
20 set flagMeaning(NoColumns) {OP_ResultRow called with zero columns}
21 set flagMeaning(NoColumns1) {zero columns if RHS argument is present}
23 set pragma_def {
24 NAME: full_column_names
25 TYPE: FLAG
26 ARG: SQLITE_FullColNames
27 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
29 NAME: short_column_names
30 TYPE: FLAG
31 ARG: SQLITE_ShortColNames
32 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
34 NAME: count_changes
35 TYPE: FLAG
36 ARG: SQLITE_CountRows
37 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
39 NAME: empty_result_callbacks
40 TYPE: FLAG
41 ARG: SQLITE_NullCallback
42 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
44 NAME: legacy_file_format
45 TYPE: FLAG
46 ARG: SQLITE_LegacyFileFmt
47 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
49 NAME: fullfsync
50 TYPE: FLAG
51 ARG: SQLITE_FullFSync
52 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
54 NAME: checkpoint_fullfsync
55 TYPE: FLAG
56 ARG: SQLITE_CkptFullFSync
57 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
59 NAME: cache_spill
60 FLAG: Result0 SchemaReq NoColumns1
61 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
63 NAME: reverse_unordered_selects
64 TYPE: FLAG
65 ARG: SQLITE_ReverseOrder
66 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
68 NAME: query_only
69 TYPE: FLAG
70 ARG: SQLITE_QueryOnly
71 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
73 NAME: automatic_index
74 TYPE: FLAG
75 ARG: SQLITE_AutoIndex
76 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
77 IF: !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
79 NAME: sql_trace
80 TYPE: FLAG
81 ARG: SQLITE_SqlTrace
82 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
83 IF: defined(SQLITE_DEBUG)
85 NAME: vdbe_listing
86 TYPE: FLAG
87 ARG: SQLITE_VdbeListing
88 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
89 IF: defined(SQLITE_DEBUG)
91 NAME: vdbe_trace
92 TYPE: FLAG
93 ARG: SQLITE_VdbeTrace
94 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
95 IF: defined(SQLITE_DEBUG)
97 NAME: vdbe_addoptrace
98 TYPE: FLAG
99 ARG: SQLITE_VdbeAddopTrace
100 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
101 IF: defined(SQLITE_DEBUG)
103 NAME: vdbe_debug
104 TYPE: FLAG
105 ARG: SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace
106 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
107 IF: defined(SQLITE_DEBUG)
109 NAME: vdbe_eqp
110 TYPE: FLAG
111 ARG: SQLITE_VdbeEQP
112 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
113 IF: defined(SQLITE_DEBUG)
115 NAME: ignore_check_constraints
116 TYPE: FLAG
117 ARG: SQLITE_IgnoreChecks
118 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
119 IF: !defined(SQLITE_OMIT_CHECK)
121 NAME: writable_schema
122 TYPE: FLAG
123 ARG: SQLITE_WriteSchema
124 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
126 NAME: read_uncommitted
127 TYPE: FLAG
128 ARG: SQLITE_ReadUncommit
129 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
131 NAME: recursive_triggers
132 TYPE: FLAG
133 ARG: SQLITE_RecTriggers
134 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
136 NAME: foreign_keys
137 TYPE: FLAG
138 ARG: SQLITE_ForeignKeys
139 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
140 IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
142 NAME: defer_foreign_keys
143 TYPE: FLAG
144 ARG: SQLITE_DeferFKs
145 IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS)
146 IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
148 NAME: cell_size_check
149 TYPE: FLAG
150 ARG: SQLITE_CellSizeCk
152 NAME: default_cache_size
153 FLAG: NeedSchema Result0 SchemaReq NoColumns1
154 COLS: cache_size
155 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
157 NAME: page_size
158 FLAG: Result0 SchemaReq NoColumns1
159 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
161 NAME: secure_delete
162 FLAG: Result0
163 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
165 NAME: page_count
166 FLAG: NeedSchema Result0 SchemaReq
167 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
169 NAME: max_page_count
170 TYPE: PAGE_COUNT
171 FLAG: NeedSchema Result0 SchemaReq
172 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
174 NAME: locking_mode
175 FLAG: Result0 SchemaReq
176 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
178 NAME: journal_mode
179 FLAG: NeedSchema Result0 SchemaReq
180 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
182 NAME: journal_size_limit
183 FLAG: Result0 SchemaReq
184 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
186 NAME: cache_size
187 FLAG: NeedSchema Result0 SchemaReq NoColumns1
188 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
190 NAME: mmap_size
191 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
193 NAME: auto_vacuum
194 FLAG: NeedSchema Result0 SchemaReq NoColumns1
195 IF: !defined(SQLITE_OMIT_AUTOVACUUM)
197 NAME: incremental_vacuum
198 FLAG: NeedSchema NoColumns
199 IF: !defined(SQLITE_OMIT_AUTOVACUUM)
201 NAME: temp_store
202 FLAG: Result0 NoColumns1
203 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
205 NAME: temp_store_directory
206 FLAG: NoColumns1
207 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
209 NAME: data_store_directory
210 FLAG: NoColumns1
211 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
213 NAME: lock_proxy_file
214 FLAG: NoColumns1
215 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
217 NAME: synchronous
218 FLAG: NeedSchema Result0 SchemaReq NoColumns1
219 IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
221 NAME: table_info
222 FLAG: NeedSchema Result1 SchemaOpt
223 COLS: cid name type notnull dflt_value pk
224 IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
226 NAME: stats
227 FLAG: NeedSchema Result0 SchemaReq
228 COLS: tbl idx wdth hght flgs
229 IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
231 NAME: index_info
232 TYPE: INDEX_INFO
233 ARG: 0
234 FLAG: NeedSchema Result1 SchemaOpt
235 COLS: seqno cid name
236 IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
238 NAME: index_xinfo
239 TYPE: INDEX_INFO
240 ARG: 1
241 FLAG: NeedSchema Result1 SchemaOpt
242 COLS: seqno cid name desc coll key
243 IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
245 NAME: index_list
246 FLAG: NeedSchema Result1 SchemaOpt
247 COLS: seq name unique origin partial
248 IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
250 NAME: database_list
251 FLAG: NeedSchema Result0
252 COLS: seq name file
253 IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
255 NAME: function_list
256 FLAG: Result0
257 COLS: name builtin
258 IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
259 IF: defined(SQLITE_INTROSPECTION_PRAGMAS)
261 NAME: module_list
262 FLAG: Result0
263 COLS: name
264 IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
265 IF: !defined(SQLITE_OMIT_VIRTUALTABLE)
266 IF: defined(SQLITE_INTROSPECTION_PRAGMAS)
268 NAME: pragma_list
269 FLAG: Result0
270 COLS: name
271 IF: defined(SQLITE_INTROSPECTION_PRAGMAS)
273 NAME: collation_list
274 FLAG: Result0
275 COLS: seq name
276 IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
278 NAME: foreign_key_list
279 FLAG: NeedSchema Result1 SchemaOpt
280 COLS: id seq table from to on_update on_delete match
281 IF: !defined(SQLITE_OMIT_FOREIGN_KEY)
283 NAME: foreign_key_check
284 FLAG: NeedSchema Result0
285 COLS: table rowid parent fkid
286 IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
288 NAME: parser_trace
289 IF: defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_PARSER_TRACE)
291 NAME: case_sensitive_like
292 FLAG: NoColumns
294 NAME: integrity_check
295 FLAG: NeedSchema Result0 Result1
296 IF: !defined(SQLITE_OMIT_INTEGRITY_CHECK)
298 NAME: quick_check
299 TYPE: INTEGRITY_CHECK
300 FLAG: NeedSchema Result0 Result1
301 IF: !defined(SQLITE_OMIT_INTEGRITY_CHECK)
303 NAME: encoding
304 FLAG: Result0 NoColumns1
305 IF: !defined(SQLITE_OMIT_UTF16)
307 NAME: schema_version
308 TYPE: HEADER_VALUE
309 ARG: BTREE_SCHEMA_VERSION
310 FLAG: NoColumns1 Result0
311 IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
313 NAME: user_version
314 TYPE: HEADER_VALUE
315 ARG: BTREE_USER_VERSION
316 FLAG: NoColumns1 Result0
317 IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
319 NAME: data_version
320 TYPE: HEADER_VALUE
321 ARG: BTREE_DATA_VERSION
322 FLAG: ReadOnly Result0
323 IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
325 NAME: freelist_count
326 TYPE: HEADER_VALUE
327 ARG: BTREE_FREE_PAGE_COUNT
328 FLAG: ReadOnly Result0
329 IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
331 NAME: application_id
332 TYPE: HEADER_VALUE
333 ARG: BTREE_APPLICATION_ID
334 FLAG: NoColumns1 Result0
335 IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
337 NAME: compile_options
338 FLAG: Result0
339 IF: !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
341 NAME: wal_checkpoint
342 FLAG: NeedSchema
343 COLS: busy log checkpointed
344 IF: !defined(SQLITE_OMIT_WAL)
346 NAME: wal_autocheckpoint
347 IF: !defined(SQLITE_OMIT_WAL)
349 NAME: shrink_memory
350 FLAG: NoColumns
352 NAME: busy_timeout
353 FLAG: Result0
354 COLS: timeout
356 NAME: lock_status
357 FLAG: Result0
358 COLS: database status
359 IF: defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
361 NAME: key
362 IF: defined(SQLITE_HAS_CODEC)
364 NAME: rekey
365 IF: defined(SQLITE_HAS_CODEC)
367 NAME: hexkey
368 IF: defined(SQLITE_HAS_CODEC)
370 NAME: hexrekey
371 TYPE: HEXKEY
372 IF: defined(SQLITE_HAS_CODEC)
374 NAME: activate_extensions
375 IF: defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
377 NAME: soft_heap_limit
378 FLAG: Result0
380 NAME: threads
381 FLAG: Result0
383 NAME: optimize
384 FLAG: Result1 NeedSchema
387 # Open the output file
389 set destfile "[file dir [file dir [file normal $argv0]]]/src/pragma.h"
390 puts "Overwriting $destfile with new pragma table..."
391 set fd [open $destfile wb]
392 puts $fd {/* DO NOT EDIT!
393 ** This file is automatically generated by the script at
394 ** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit
395 ** that script and rerun it.
398 # Parse the PRAGMA table above.
400 set name {}
401 set type {}
402 set if {}
403 set flags {}
404 set cols {}
405 set cols_list {}
406 set arg 0
407 proc record_one {} {
408 global name type if arg allbyname typebyif flags cols allcols
409 global cols_list colUsedBy
410 if {$name==""} return
411 if {$cols!=""} {
412 if {![info exists allcols($cols)]} {
413 lappend cols_list $cols
414 set allcols($cols) [llength $cols_list]
416 set cx $allcols($cols)
417 lappend colUsedBy($cols) $name
418 } else {
419 set cx 0
421 set allbyname($name) [list $type $arg $if $flags $cx]
422 set name {}
423 set type {}
424 set if {}
425 set flags {}
426 set cols {}
427 set arg 0
429 foreach line [split $pragma_def \n] {
430 set line [string trim $line]
431 if {$line==""} continue
432 foreach {id val} [split $line :] break
433 set val [string trim $val]
434 if {$id=="NAME"} {
435 record_one
436 set name $val
437 set type [string toupper $val]
438 } elseif {$id=="TYPE"} {
439 set type $val
440 if {$type=="FLAG"} {
441 lappend flags Result0 NoColumns1
443 } elseif {$id=="ARG"} {
444 set arg $val
445 } elseif {$id=="COLS"} {
446 set cols $val
447 } elseif {$id=="IF"} {
448 lappend if $val
449 } elseif {$id=="FLAG"} {
450 foreach term [split $val] {
451 lappend flags $term
452 set allflags($term) 1
454 } else {
455 error "bad pragma_def line: $line"
458 record_one
459 set allnames [lsort [array names allbyname]]
461 # Generate #defines for all pragma type names. Group the pragmas that are
462 # omit in default builds (defined(SQLITE_DEBUG) and defined(SQLITE_HAS_CODEC))
463 # at the end.
465 puts $fd "\n/* The various pragma types */"
466 set pnum 0
467 foreach name $allnames {
468 set type [lindex $allbyname($name) 0]
469 if {[info exists seentype($type)]} continue
470 set if [lindex $allbyname($name) 2]
471 if {[regexp SQLITE_DEBUG $if] || [regexp SQLITE_HAS_CODEC $if]} continue
472 set seentype($type) 1
473 puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum]
474 incr pnum
476 foreach name $allnames {
477 set type [lindex $allbyname($name) 0]
478 if {[info exists seentype($type)]} continue
479 set if [lindex $allbyname($name) 2]
480 if {[regexp SQLITE_DEBUG $if]} continue
481 set seentype($type) 1
482 puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum]
483 incr pnum
485 foreach name $allnames {
486 set type [lindex $allbyname($name) 0]
487 if {[info exists seentype($type)]} continue
488 set seentype($type) 1
489 puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum]
490 incr pnum
493 # Generate #defines for flags
495 puts $fd "\n/* Property flags associated with various pragma. */"
496 set fv 1
497 foreach f [lsort [array names allflags]] {
498 puts $fd [format {#define PragFlg_%-10s 0x%02x /* %s */} \
499 $f $fv $flagMeaning($f)]
500 set fv [expr {$fv*2}]
503 # Generate the array of column names used by pragmas that act like
504 # queries.
506 puts $fd "\n/* Names of columns for pragmas that return multi-column result"
507 puts $fd "** or that return single-column results where the name of the"
508 puts $fd "** result column is different from the name of the pragma\n*/"
509 puts $fd "static const char *const pragCName\[\] = {"
510 set offset 0
511 foreach cols $cols_list {
512 set cols_offset($allcols($cols)) $offset
513 set ub " /* Used by: $colUsedBy($cols) */"
514 foreach c $cols {
515 puts $fd [format " /* %3d */ %-14s%s" $offset \"$c\", $ub]
516 set ub ""
517 incr offset
520 puts $fd "\175;"
522 # Generate the lookup table
524 puts $fd "\n/* Definitions of all built-in pragmas */"
525 puts $fd "typedef struct PragmaName \173"
526 puts $fd " const char *const zName; /* Name of pragma */"
527 puts $fd " u8 ePragTyp; /* PragTyp_XXX value */"
528 puts $fd " u8 mPragFlg; /* Zero or more PragFlg_XXX values */"
529 puts $fd { u8 iPragCName; /* Start of column names in pragCName[] */}
530 puts $fd " u8 nPragCName; \
531 /* Num of col names. 0 means use pragma name */"
532 puts $fd " u32 iArg; /* Extra argument */"
533 puts $fd "\175 PragmaName;"
534 puts $fd "static const PragmaName aPragmaName\[\] = \173"
536 set current_if {}
537 set spacer [format { %26s } {}]
538 foreach name $allnames {
539 foreach {type arg if flag cx} $allbyname($name) break
540 if {$cx==0} {
541 set cy 0
542 set nx 0
543 } else {
544 set cy $cols_offset($cx)
545 set nx [llength [lindex $cols_list [expr {$cx-1}]]]
547 if {$if!=$current_if} {
548 if {$current_if!=""} {
549 foreach this_if $current_if {
550 puts $fd "#endif"
553 set current_if $if
554 if {$current_if!=""} {
555 foreach this_if $current_if {
556 puts $fd "#if $this_if"
560 set typex [format PragTyp_%-23s $type,]
561 if {$flag==""} {
562 set flagx "0"
563 } else {
564 set flagx PragFlg_[join $flag {|PragFlg_}]
566 puts $fd " \173/* zName: */ \"$name\","
567 puts $fd " /* ePragTyp: */ PragTyp_$type,"
568 puts $fd " /* ePragFlg: */ $flagx,"
569 puts $fd " /* ColNames: */ $cy, $nx,"
570 puts $fd " /* iArg: */ $arg \175,"
572 if {$current_if!=""} {
573 foreach this_if $current_if {
574 puts $fd "#endif"
577 puts $fd "\175;"
579 # count the number of pragmas, for information purposes
581 set allcnt 0
582 set dfltcnt 0
583 foreach name $allnames {
584 incr allcnt
585 set if [lindex $allbyname($name) 2]
586 if {[regexp {^defined} $if] || [regexp {[^!]defined} $if]} continue
587 incr dfltcnt
589 puts $fd "/* Number of pragmas: $dfltcnt on by default, $allcnt total. */"