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.
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
}
24 NAME
: full_column_names
26 ARG
: SQLITE_FullColNames
27 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
29 NAME
: short_column_names
31 ARG
: SQLITE_ShortColNames
32 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
37 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
39 NAME
: empty_result_callbacks
41 ARG
: SQLITE_NullCallback
42 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
44 NAME
: legacy_file_format
46 ARG
: SQLITE_LegacyFileFmt
47 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
52 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
54 NAME
: checkpoint_fullfsync
56 ARG
: SQLITE_CkptFullFSync
57 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
60 FLAG
: Result0 SchemaReq NoColumns1
61 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
63 NAME
: reverse_unordered_selects
65 ARG
: SQLITE_ReverseOrder
66 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
71 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
76 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
77 IF
: !defined
(SQLITE_OMIT_AUTOMATIC_INDEX
)
82 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
83 IF
: defined
(SQLITE_DEBUG
)
87 ARG
: SQLITE_VdbeListing
88 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
89 IF
: defined
(SQLITE_DEBUG
)
94 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
95 IF
: defined
(SQLITE_DEBUG
)
99 ARG
: SQLITE_VdbeAddopTrace
100 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
101 IF
: defined
(SQLITE_DEBUG
)
105 ARG
: SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace
106 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
107 IF
: defined
(SQLITE_DEBUG
)
112 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
113 IF
: defined
(SQLITE_DEBUG
)
115 NAME
: ignore_check_constraints
117 ARG
: SQLITE_IgnoreChecks
118 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
119 IF
: !defined
(SQLITE_OMIT_CHECK
)
121 NAME
: writable_schema
123 ARG
: SQLITE_WriteSchema|SQLITE_NoSchemaError
124 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
126 NAME
: read_uncommitted
128 ARG
: SQLITE_ReadUncommit
129 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
131 NAME
: recursive_triggers
133 ARG
: SQLITE_RecTriggers
134 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
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
145 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
146 IF
: !defined
(SQLITE_OMIT_FOREIGN_KEY
) && !defined
(SQLITE_OMIT_TRIGGER
)
148 NAME
: cell_size_check
150 ARG
: SQLITE_CellSizeCk
152 NAME
: default_cache_size
153 FLAG
: NeedSchema Result0 SchemaReq NoColumns1
155 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
) && !defined
(SQLITE_OMIT_DEPRECATED
)
158 FLAG
: Result0 SchemaReq NoColumns1
159 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
163 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
166 FLAG
: NeedSchema Result0 SchemaReq
167 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
171 FLAG
: NeedSchema Result0 SchemaReq
172 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
175 FLAG
: Result0 SchemaReq
176 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
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
)
187 FLAG
: NeedSchema Result0 SchemaReq NoColumns1
188 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
191 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
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
)
202 FLAG
: Result0 NoColumns1
203 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
205 NAME
: temp_store_directory
207 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
209 NAME
: data_store_directory
211 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
) && SQLITE_OS_WIN
213 NAME
: lock_proxy_file
215 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
) && SQLITE_ENABLE_LOCKING_STYLE
218 FLAG
: NeedSchema Result0 SchemaReq NoColumns1
219 IF
: !defined
(SQLITE_OMIT_PAGER_PRAGMAS
)
222 FLAG
: NeedSchema Result1 SchemaOpt
224 COLS
: cid name type notnull dflt_value pk
225 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
229 FLAG
: NeedSchema Result1 SchemaOpt
231 COLS
: cid name type notnull dflt_value pk hidden
232 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
235 FLAG
: NeedSchema Result0 SchemaReq
236 COLS
: tbl idx wdth hght flgs
237 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
) && defined
(SQLITE_DEBUG
)
242 FLAG
: NeedSchema Result1 SchemaOpt
244 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
249 FLAG
: NeedSchema Result1 SchemaOpt
250 COLS
: seqno cid name desc coll key
251 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
254 FLAG
: NeedSchema Result1 SchemaOpt
255 COLS
: seq name unique origin partial
256 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
259 FLAG
: NeedSchema Result0
261 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
266 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
267 IF
: defined
(SQLITE_INTROSPECTION_PRAGMAS
)
272 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
273 IF
: !defined
(SQLITE_OMIT_VIRTUALTABLE
)
274 IF
: defined
(SQLITE_INTROSPECTION_PRAGMAS
)
279 IF
: defined
(SQLITE_INTROSPECTION_PRAGMAS
)
284 IF
: !defined
(SQLITE_OMIT_SCHEMA_PRAGMAS
)
286 NAME
: foreign_key_list
287 FLAG
: NeedSchema Result1 SchemaOpt
288 COLS
: id seq table from to on_update on_delete match
289 IF
: !defined
(SQLITE_OMIT_FOREIGN_KEY
)
291 NAME
: foreign_key_check
292 FLAG
: NeedSchema Result0
293 COLS
: table rowid parent fkid
294 IF
: !defined
(SQLITE_OMIT_FOREIGN_KEY
) && !defined
(SQLITE_OMIT_TRIGGER
)
297 IF
: defined
(SQLITE_DEBUG
) && !defined
(SQLITE_OMIT_PARSER_TRACE
)
299 NAME
: case_sensitive_like
302 NAME
: integrity_check
303 FLAG
: NeedSchema Result0 Result1
304 IF
: !defined
(SQLITE_OMIT_INTEGRITY_CHECK
)
307 TYPE
: INTEGRITY_CHECK
308 FLAG
: NeedSchema Result0 Result1
309 IF
: !defined
(SQLITE_OMIT_INTEGRITY_CHECK
)
312 FLAG
: Result0 NoColumns1
313 IF
: !defined
(SQLITE_OMIT_UTF16
)
317 ARG
: BTREE_SCHEMA_VERSION
318 FLAG
: NoColumns1 Result0
319 IF
: !defined
(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
)
323 ARG
: BTREE_USER_VERSION
324 FLAG
: NoColumns1 Result0
325 IF
: !defined
(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
)
329 ARG
: BTREE_DATA_VERSION
330 FLAG
: ReadOnly Result0
331 IF
: !defined
(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
)
335 ARG
: BTREE_FREE_PAGE_COUNT
336 FLAG
: ReadOnly Result0
337 IF
: !defined
(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
)
341 ARG
: BTREE_APPLICATION_ID
342 FLAG
: NoColumns1 Result0
343 IF
: !defined
(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
)
345 NAME
: compile_options
347 IF
: !defined
(SQLITE_OMIT_COMPILEOPTION_DIAGS
)
351 COLS
: busy log checkpointed
352 IF
: !defined
(SQLITE_OMIT_WAL
)
354 NAME
: wal_autocheckpoint
355 IF
: !defined
(SQLITE_OMIT_WAL
)
366 COLS
: database status
367 IF
: defined
(SQLITE_DEBUG
) || defined
(SQLITE_TEST
)
372 IF
: defined
(SQLITE_HAS_CODEC
)
377 IF
: defined
(SQLITE_HAS_CODEC
)
382 IF
: defined
(SQLITE_HAS_CODEC
)
387 IF
: defined
(SQLITE_HAS_CODEC
)
392 IF
: defined
(SQLITE_HAS_CODEC
)
397 IF
: defined
(SQLITE_HAS_CODEC
)
399 NAME
: activate_extensions
400 IF
: defined
(SQLITE_HAS_CODEC
) || defined
(SQLITE_ENABLE_CEROD
)
402 NAME
: soft_heap_limit
409 FLAG
: Result1 NeedSchema
411 NAME
: legacy_alter_table
413 ARG
: SQLITE_LegacyAlter
414 IF
: !defined
(SQLITE_OMIT_FLAG_PRAGMAS
)
417 # Open the output file
419 set destfile
"[file dir [file dir [file normal $argv0]]]/src/pragma.h"
420 puts "Overwriting $destfile with new pragma table..."
421 set fd
[open $destfile wb
]
422 puts $fd {/* DO NOT EDIT
!
423 ** This
file is automatically generated by the script at
424 ** ..
/tool
/mkpragmatab.tcl. To
update the
set of pragmas
, edit
425 ** that script and rerun it.
428 # Parse the PRAGMA table above.
438 global name type
if arg allbyname typebyif flags cols all_cols
439 global cols_list colUsedBy
440 if {$name==""} return
442 if {![info exists all_cols
($cols)]} {
443 set all_cols
($cols) 1
444 lappend cols_list
$cols
447 lappend colUsedBy
($cols) $name
451 set allbyname
($name) [list $type $arg $if $flags $cols]
459 foreach line
[split $pragma_def \n] {
460 set line
[string trim
$line]
461 if {$line==""} continue
462 foreach {id val
} [split $line :] break
463 set val
[string trim
$val]
467 set type
[string toupper
$val]
468 } elseif
{$id=="TYPE"} {
471 lappend flags Result0 NoColumns1
473 } elseif
{$id=="ARG"} {
475 } elseif
{$id=="COLS"} {
477 } elseif
{$id=="IF"} {
479 } elseif
{$id=="FLAG"} {
480 foreach term
[split $val] {
482 set allflags
($term) 1
485 error "bad pragma_def line: $line"
489 set allnames
[lsort [array names allbyname
]]
491 # Generate #defines for all pragma type names. Group the pragmas that are
492 # omit in default builds (defined(SQLITE_DEBUG) and defined(SQLITE_HAS_CODEC))
495 puts $fd "\n/* The various pragma types */"
497 foreach name
$allnames {
498 set type
[lindex $allbyname($name) 0]
499 if {[info exists seentype
($type)]} continue
500 set if [lindex $allbyname($name) 2]
501 if {[regexp SQLITE_DEBUG
$if] ||
[regexp SQLITE_HAS_CODEC
$if]} continue
502 set seentype
($type) 1
503 puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum]
506 foreach name
$allnames {
507 set type
[lindex $allbyname($name) 0]
508 if {[info exists seentype
($type)]} continue
509 set if [lindex $allbyname($name) 2]
510 if {[regexp SQLITE_DEBUG
$if]} continue
511 set seentype
($type) 1
512 puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum]
515 foreach name
$allnames {
516 set type
[lindex $allbyname($name) 0]
517 if {[info exists seentype
($type)]} continue
518 set seentype
($type) 1
519 puts $fd [format {#define %-35s %4d} PragTyp_$type $pnum]
523 # Generate #defines for flags
525 puts $fd "\n/* Property flags associated with various pragma. */"
527 foreach f
[lsort [array names allflags
]] {
528 puts $fd [format {#define PragFlg_%-10s 0x%02x /* %s */} \
529 $f $fv $flagMeaning($f)]
530 set fv
[expr {$fv*2}]
533 # Sort the column lists so that longer column lists occur first
536 return [expr {[llength $b] - [llength $a]}]
538 set cols_list
[lsort -command colscmp
$cols_list]
540 # Generate the array of column names used by pragmas that act like
543 puts $fd "\n/* Names of columns for pragmas that return multi-column result"
544 puts $fd "** or that return single-column results where the name of the"
545 puts $fd "** result column is different from the name of the pragma\n*/"
546 puts $fd "static const char *const pragCName\[\] = {"
549 foreach cols
$cols_list {
550 set n
[llength $cols]
551 set limit
[expr {[llength $allcollist] - $n}]
552 for {set i
0} {$i<$limit} {incr i
} {
553 set sublist
[lrange $allcollist $i [expr {$i+$n-1}]]
554 if {$sublist==$cols} {
555 puts $fd [format "%27s/* $colUsedBy($cols) reuses $i */" ""]
556 set cols_offset
($cols) $i
560 if {$i<$limit} continue
561 set cols_offset
($cols) $offset
562 set ub
" /* Used by: $colUsedBy($cols) */"
564 lappend allcollist
$c
565 puts $fd [format " /* %3d */ %-14s%s" $offset \"$c\", $ub]
572 # Generate the lookup table
574 puts $fd "\n/* Definitions of all built-in pragmas */"
575 puts $fd "typedef struct PragmaName \173"
576 puts $fd " const char *const zName; /* Name of pragma */"
577 puts $fd " u8 ePragTyp; /* PragTyp_XXX value */"
578 puts $fd " u8 mPragFlg; /* Zero or more PragFlg_XXX values */"
579 puts $fd { u8 iPragCName
; /* Start of column names in pragCName
[] */}
580 puts $fd " u8 nPragCName; \
581 /* Num of col names. 0 means use pragma name */"
582 puts $fd " u64 iArg; /* Extra argument */"
583 puts $fd "\175 PragmaName;"
584 puts $fd "static const PragmaName aPragmaName\[\] = \173"
587 set spacer
[format { %26s
} {}]
588 foreach name
$allnames {
589 foreach {type arg
if flag cx
} $allbyname($name) break
590 if {$cx==0 ||
$cx==""} {
594 set cy
$cols_offset($cx)
597 if {$if!=$current_if} {
598 if {$current_if!=""} {
599 foreach this_if
$current_if {
604 if {$current_if!=""} {
605 foreach this_if
$current_if {
606 puts $fd "#if $this_if"
610 set typex
[format PragTyp_
%-23s $type,]
614 set flagx PragFlg_
[join $flag {|PragFlg_
}]
616 puts $fd " \173/* zName: */ \"$name\","
617 puts $fd " /* ePragTyp: */ PragTyp_$type,"
618 puts $fd " /* ePragFlg: */ $flagx,"
619 puts $fd " /* ColNames: */ $cy, $nx,"
620 puts $fd " /* iArg: */ $arg \175,"
622 if {$current_if!=""} {
623 foreach this_if
$current_if {
629 # count the number of pragmas, for information purposes
633 foreach name
$allnames {
635 set if [lindex $allbyname($name) 2]
636 if {[regexp {^defined
} $if] ||
[regexp {[^
!]defined
} $if]} continue
639 puts $fd "/* Number of pragmas: $dfltcnt on by default, $allcnt total. */"