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.
12 # The results are normally written into the ../src/pragma.h file. However,
13 # if an alternative output file name is provided as an argument, then
14 # results are written into the alternative. For example:
16 # tclsh tool/mkpragmatab.tcl ;# <--- Results to src/pragma.h
18 # tclsh tool/mkpragmatab.tcl /dev/tty ;# <-- results to terminal
22 set flagMeaning
(NeedSchema
) {Force schema
load before running
}
23 set flagMeaning
(ReadOnly
) {Read-only HEADER_VALUE
}
24 set flagMeaning
(Result0
) {Acts as query when no argument
}
25 set flagMeaning
(Result1
) {Acts as query when has one argument
}
26 set flagMeaning
(SchemaReq
) {Schema required
- "main" is
default}
27 set flagMeaning
(SchemaOpt
) {Schema restricts name search
if present
}
28 set flagMeaning
(NoColumns
) {OP_ResultRow called with zero columns
}
29 set flagMeaning
(NoColumns1
) {zero columns
if RHS argument is present
}
32 NAME
: full_column_names
34 ARG
: SQLITE_FullColNames
35 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
37 NAME
: short_column_names
39 ARG
: SQLITE_ShortColNames
40 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
45 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
47 NAME
: empty_result_callbacks
49 ARG
: SQLITE_NullCallback
50 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
55 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
57 NAME
: checkpoint_fullfsync
59 ARG
: SQLITE_CkptFullFSync
60 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
63 FLAG
: Result0 SchemaReq NoColumns1
64 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
66 NAME
: reverse_unordered_selects
68 ARG
: SQLITE_ReverseOrder
69 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
74 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
79 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
80 IF
: !defined
(SQLITE_OMIT_AUTOMATIC_INDEX
)
85 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
86 IF
: defined
(SQLITE_DEBUG
)
90 ARG
: SQLITE_VdbeListing
91 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
92 IF
: defined
(SQLITE_DEBUG
)
97 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
98 IF
: defined
(SQLITE_DEBUG
)
100 NAME
: vdbe_addoptrace
102 ARG
: SQLITE_VdbeAddopTrace
103 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
104 IF
: defined
(SQLITE_DEBUG
)
108 ARG
: SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace
109 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
110 IF
: defined
(SQLITE_DEBUG
)
115 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
116 IF
: defined
(SQLITE_DEBUG
)
118 NAME
: ignore_check_constraints
120 ARG
: SQLITE_IgnoreChecks
121 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
122 IF
: !defined
(SQLITE_OMIT_CHECK
)
124 NAME
: writable_schema
126 ARG
: SQLITE_WriteSchema|SQLITE_NoSchemaError
127 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
129 NAME
: read_uncommitted
131 ARG
: SQLITE_ReadUncommit
132 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
134 NAME
: recursive_triggers
136 ARG
: SQLITE_RecTriggers
137 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
141 ARG
: SQLITE_TrustedSchema
142 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
146 ARG
: SQLITE_ForeignKeys
147 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
148 IF
: !defined
(SQLITE_OMIT_FOREIGN_KEY
) && !defined
(SQLITE_OMIT_TRIGGER
)
150 NAME
: defer_foreign_keys
153 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
154 IF
: !defined
(SQLITE_OMIT_FOREIGN_KEY
) && !defined
(SQLITE_OMIT_TRIGGER
)
156 NAME
: cell_size_check
158 ARG
: SQLITE_CellSizeCk
160 NAME
: default_cache_size
161 FLAG
: NeedSchema Result0 SchemaReq NoColumns1
163 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
) && !defined
(SQLITE_OMIT_DEPRECATED
)
166 FLAG
: Result0 SchemaReq NoColumns1
167 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
171 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
174 FLAG
: NeedSchema Result0 SchemaReq
175 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
179 FLAG
: NeedSchema Result0 SchemaReq
180 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
183 FLAG
: Result0 SchemaReq
184 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
187 FLAG
: NeedSchema Result0 SchemaReq
188 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
190 NAME
: journal_size_limit
191 FLAG
: Result0 SchemaReq
192 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
195 FLAG
: NeedSchema Result0 SchemaReq NoColumns1
196 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
199 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
202 FLAG
: NeedSchema Result0 SchemaReq NoColumns1
203 IF
: !defined
(SQLITE_OMIT_AUTOVACUUM
)
205 NAME
: incremental_vacuum
206 FLAG
: NeedSchema NoColumns
207 IF
: !defined
(SQLITE_OMIT_AUTOVACUUM
)
210 FLAG
: Result0 NoColumns1
211 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
213 NAME
: temp_store_directory
215 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
217 NAME
: data_store_directory
219 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
) && SQLITE_OS_WIN
221 NAME
: lock_proxy_file
223 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
) && SQLITE_ENABLE_LOCKING_STYLE
226 FLAG
: NeedSchema Result0 SchemaReq NoColumns1
227 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
230 FLAG
: NeedSchema Result1 SchemaOpt
232 COLS
: cid name type notnull dflt_value pk
233 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
237 FLAG
: NeedSchema Result1 SchemaOpt
239 COLS
: cid name type notnull dflt_value pk hidden
240 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
244 FLAG
: NeedSchema Result1
245 COLS
: schema name type ncol wr strict
246 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
249 FLAG
: NeedSchema Result0 SchemaReq
250 COLS
: tbl idx wdth hght flgs
251 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
) && defined
(SQLITE_DEBUG
)
256 FLAG
: NeedSchema Result1 SchemaOpt
258 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
263 FLAG
: NeedSchema Result1 SchemaOpt
264 COLS
: seqno cid name desc coll key
265 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
268 FLAG
: NeedSchema Result1 SchemaOpt
269 COLS
: seq name unique origin partial
270 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
275 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
279 COLS
: name builtin type enc narg flags
280 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
281 IF
: !defined
(SQLITE_OMIT_INTROSPECTION_PRAGMAS
)
286 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
287 IF
: !defined
(SQLITE_OMIT_VIRTUALTABLE
)
288 IF
: !defined
(SQLITE_OMIT_INTROSPECTION_PRAGMAS
)
293 IF
: !defined
(SQLITE_OMIT_INTROSPECTION_PRAGMAS
)
298 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
300 NAME
: foreign_key_list
301 FLAG
: NeedSchema Result1 SchemaOpt
302 COLS
: id seq table from to on_update on_delete match
303 IF
: !defined
(SQLITE_OMIT_FOREIGN_KEY
)
305 NAME
: foreign_key_check
306 FLAG
: NeedSchema Result0 Result1 SchemaOpt
307 COLS
: table rowid parent fkid
308 IF
: !defined
(SQLITE_OMIT_FOREIGN_KEY
) && !defined
(SQLITE_OMIT_TRIGGER
)
312 ARG
: SQLITE_ParserTrace
313 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
314 IF
: defined
(SQLITE_DEBUG
)
316 NAME
: case_sensitive_like
318 IF
: !defined
(SQLITE_OMIT_CASE_SENSITIVE_LIKE_PRAGMA
)
320 NAME
: integrity_check
321 FLAG
: NeedSchema Result0 Result1 SchemaOpt
322 IF
: !defined
(SQLITE_OMIT_INTEGRITY_CHECK
)
325 TYPE
: INTEGRITY_CHECK
326 FLAG
: NeedSchema Result0 Result1 SchemaOpt
327 IF
: !defined
(SQLITE_OMIT_INTEGRITY_CHECK
)
330 FLAG
: Result0 NoColumns1
331 IF
: !defined
(SQLITE_OMIT_UTF16
)
335 ARG
: BTREE_SCHEMA_VERSION
336 FLAG
: NoColumns1 Result0
337 IF
: !defined
(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
)
341 ARG
: BTREE_USER_VERSION
342 FLAG
: NoColumns1 Result0
343 IF
: !defined
(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
)
347 ARG
: BTREE_DATA_VERSION
348 FLAG
: ReadOnly Result0
349 IF
: !defined
(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
)
353 ARG
: BTREE_FREE_PAGE_COUNT
354 FLAG
: ReadOnly Result0
355 IF
: !defined
(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
)
359 ARG
: BTREE_APPLICATION_ID
360 FLAG
: NoColumns1 Result0
361 IF
: !defined
(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
)
363 NAME
: compile_options
365 IF
: !defined
(SQLITE_OMIT_COMPILEOPTION_DIAGS
)
369 COLS
: busy log checkpointed
370 IF
: !defined
(SQLITE_OMIT_WAL
)
372 NAME
: wal_autocheckpoint
373 IF
: !defined
(SQLITE_OMIT_WAL
)
384 COLS
: database status
385 IF
: defined
(SQLITE_DEBUG
) || defined
(SQLITE_TEST
)
387 NAME
: activate_extensions
388 IF
: defined
(SQLITE_ENABLE_CEROD
)
390 NAME
: soft_heap_limit
393 NAME
: hard_heap_limit
403 FLAG
: Result1 NeedSchema
405 NAME
: legacy_alter_table
407 ARG
: SQLITE_LegacyAlter
408 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
411 # Open the output file
414 set destfile
[lindex $argv 0]
416 set destfile
"[file dir [file dir [file normal $argv0]]]/src/pragma.h"
417 puts "Overwriting $destfile with new pragma table..."
419 set fd
[open $destfile wb
]
420 puts $fd {/* DO NOT EDIT
!
421 ** This
file is automatically generated by the script at
422 ** ..
/tool
/mkpragmatab.tcl. To
update the
set of pragmas
, edit
423 ** that script and rerun it.
426 # Parse the PRAGMA table above.
436 global name type
if arg allbyname typebyif flags cols all_cols
437 global cols_list colUsedBy
438 if {$name==""} return
440 if {![info exists all_cols
($cols)]} {
441 set all_cols
($cols) 1
442 lappend cols_list
$cols
445 lappend colUsedBy
($cols) $name
449 set allbyname
($name) [list $type $arg $if $flags $cols]
457 foreach line
[split $pragma_def \n] {
458 set line
[string trim
$line]
459 if {$line==""} continue
460 foreach {id val
} [split $line :] break
461 set val
[string trim
$val]
465 set type
[string toupper
$val]
466 } elseif
{$id=="TYPE"} {
469 lappend flags Result0 NoColumns1
471 } elseif
{$id=="ARG"} {
473 } elseif
{$id=="COLS"} {
475 } elseif
{$id=="IF"} {
477 } elseif
{$id=="FLAG"} {
478 foreach term
[split $val] {
480 set allflags
($term) 1
483 error "bad pragma_def line: $line"
487 set allnames
[lsort [array names allbyname
]]
489 # Generate #defines for all pragma type names. Group the pragmas that are
490 # omit in default builds (ex: defined(SQLITE_DEBUG))
493 puts $fd "\n/* The various pragma types */"
495 foreach name
$allnames {
496 set type
[lindex $allbyname($name) 0]
497 if {[info exists seentype
($type)]} continue
498 set if [lindex $allbyname($name) 2]
499 if {[regexp SQLITE_DEBUG
$if] ||
[regexp SQLITE_HAS_CODEC
$if]} continue
500 set seentype
($type) 1
501 puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum]
504 foreach name
$allnames {
505 set type
[lindex $allbyname($name) 0]
506 if {[info exists seentype
($type)]} continue
507 set if [lindex $allbyname($name) 2]
508 if {[regexp SQLITE_DEBUG
$if]} continue
509 set seentype
($type) 1
510 puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum]
513 foreach name
$allnames {
514 set type
[lindex $allbyname($name) 0]
515 if {[info exists seentype
($type)]} continue
516 set seentype
($type) 1
517 puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum]
521 # Generate #defines for flags
523 puts $fd "\n/* Property flags associated with various pragma. */"
525 foreach f
[lsort [array names allflags
]] {
526 puts $fd [format {#define PragFlg_%-10s 0x%02x /* %s */} \
527 $f $fv $flagMeaning($f)]
528 set fv
[expr {$fv*2}]
531 # Sort the column lists so that longer column lists occur first
534 return [expr {[llength $b] - [llength $a]}]
536 set cols_list
[lsort -command colscmp
$cols_list]
538 # Generate the array of column names used by pragmas that act like
541 puts $fd "\n/* Names of columns for pragmas that return multi-column result"
542 puts $fd "** or that return single-column results where the name of the"
543 puts $fd "** result column is different from the name of the pragma\n*/"
544 puts $fd "static const char *const pragCName\[\] = {"
547 foreach cols
$cols_list {
548 set n
[llength $cols]
549 set limit
[expr {[llength $allcollist] - $n}]
550 for {set i
0} {$i<$limit} {incr i
} {
551 set sublist
[lrange $allcollist $i [expr {$i+$n-1}]]
552 if {$sublist==$cols} {
553 puts $fd [format "%27s/* $colUsedBy($cols) reuses $i */" ""]
554 set cols_offset
($cols) $i
558 if {$i<$limit} continue
559 set cols_offset
($cols) $offset
560 set ub
" /* Used by: $colUsedBy($cols) */"
562 lappend allcollist
$c
563 puts $fd [format " /* %3d */ %-14s%s" $offset \"$c\", $ub]
570 # Generate the lookup table
572 puts $fd "\n/* Definitions of all built-in pragmas */"
573 puts $fd "typedef struct PragmaName \173"
574 puts $fd " const char *const zName; /* Name of pragma */"
575 puts $fd " u8 ePragTyp; /* PragTyp_XXX value */"
576 puts $fd " u8 mPragFlg; /* Zero or more PragFlg_XXX values */"
577 puts $fd { u8 iPragCName
; /* Start of column names in pragCName
[] */}
578 puts $fd " u8 nPragCName; \
579 /* Num of col names. 0 means use pragma name */"
580 puts $fd " u64 iArg; /* Extra argument */"
581 puts $fd "\175 PragmaName;"
582 puts $fd "static const PragmaName aPragmaName\[\] = \173"
585 set spacer
[format { %26s
} {}]
586 foreach name
$allnames {
587 foreach {type arg
if flag cx
} $allbyname($name) break
588 if {$cx==0 ||
$cx==""} {
592 set cy
$cols_offset($cx)
595 if {$if!=$current_if} {
596 if {$current_if!=""} {
597 foreach this_if
$current_if {
602 if {$current_if!=""} {
603 foreach this_if
$current_if {
604 puts $fd "#if $this_if"
608 set typex
[format PragTyp_
%-23s $type,]
612 set flagx PragFlg_
[join $flag {|PragFlg_
}]
614 puts $fd " \173/* zName: */ \"$name\","
615 puts $fd " /* ePragTyp: */ PragTyp_$type,"
616 puts $fd " /* ePragFlg: */ $flagx,"
617 puts $fd " /* ColNames: */ $cy, $nx,"
618 puts $fd " /* iArg: */ $arg \175,"
620 if {$current_if!=""} {
621 foreach this_if
$current_if {
627 # count the number of pragmas, for information purposes
631 foreach name
$allnames {
633 set if [lindex $allbyname($name) 2]
634 if {[regexp {^defined
} $if] ||
[regexp {[^
!]defined
} $if]} continue
637 puts $fd "/* Number of pragmas: $dfltcnt on by default, $allcnt total. */"