Debian Codegraph @

www/c3ref/c_deterministic.html

raw
1 <!DOCTYPE html>
2 <html><head>
3 <meta name="viewport" content="width=device-width, initial-scale=1.0">
4 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5 <link href="../sqlite.css" rel="stylesheet">
6 <title>Function Flags</title>
7 <!-- path=../ -->
8 </head>
9 <body>
10 <div class=nosearch>
11 <a href="../index.html">
12 <img class="logo" src="../images/sqlite370_banner.gif" alt="SQLite" border="0">
13 </a>
14 <div><!-- IE hack to prevent disappearing logo --></div>
15 <div class="tagline desktoponly">
16 Small. Fast. Reliable.<br>Choose any three.
17 </div>
18 <div class="menu mainmenu">
19 <ul>
20 <li><a href="../index.html">Home</a>
21 <li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a>
22 <li class='wideonly'><a href='../about.html'>About</a>
23 <li class='desktoponly'><a href="../docs.html">Documentation</a>
24 <li class='desktoponly'><a href="../download.html">Download</a>
25 <li class='wideonly'><a href='../copyright.html'>License</a>
26 <li class='desktoponly'><a href="../support.html">Support</a>
27 <li class='desktoponly'><a href="../prosupport.html">Purchase</a>
28 <li class='search' id='search_menubutton'>
29 <a href="javascript:void(0)" onclick='toggle_search()'>Search</a>
30 </ul>
31 </div>
32 <div class="menu submenu" id="submenu">
33 <ul>
34 <li><a href='../about.html'>About</a>
35 <li><a href='../docs.html'>Documentation</a>
36 <li><a href='../download.html'>Download</a>
37 <li><a href='../support.html'>Support</a>
38 <li><a href='../prosupport.html'>Purchase</a>
39 </ul>
40 </div>
41 <div class="searchmenu" id="searchmenu">
42 <form method="GET" action="../search">
43 <select name="s" id="searchtype">
44 <option value="d">Search Documentation</option>
45 <option value="c">Search Changelog</option>
46 </select>
47 <input type="text" name="q" id="searchbox" value="">
48 <input type="submit" value="Go">
49 </form>
50 </div>
51 </div>
52 <script>
53 function toggle_div(nm) {
54 var w = document.getElementById(nm);
55 if( w.style.display=="block" ){
56 w.style.display = "none";
57 }else{
58 w.style.display = "block";
59 }
60 }
61 function toggle_search() {
62 var w = document.getElementById("searchmenu");
63 if( w.style.display=="block" ){
64 w.style.display = "none";
65 } else {
66 w.style.display = "block";
67 setTimeout(function(){
68 document.getElementById("searchbox").focus()
69 }, 30);
70 }
71 }
72 function div_off(nm){document.getElementById(nm).style.display="none";}
73 window.onbeforeunload = function(e){div_off("submenu");}
74 /* Disable the Search feature if we are not operating from CGI, since */
75 /* Search is accomplished using CGI and will not work without it. */
76 if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){
77 document.getElementById("search_menubutton").style.display = "none";
78 }
79 /* Used by the Hide/Show button beside syntax diagrams, to toggle the */
80 function hideorshow(btn,obj){
81 var x = document.getElementById(obj);
82 var b = document.getElementById(btn);
83 if( x.style.display!='none' ){
84 x.style.display = 'none';
85 b.innerHTML='show';
86 }else{
87 x.style.display = '';
88 b.innerHTML='hide';
89 }
90 return false;
91 }
92 var antiRobot = 0;
93 function antiRobotGo(){
94 if( antiRobot!=3 ) return;
95 antiRobot = 7;
96 var j = document.getElementById("mtimelink");
97 if(j && j.hasAttribute("data-href")) j.href=j.getAttribute("data-href");
98 }
99 function antiRobotDefense(){
100 document.body.onmousedown=function(){
101 antiRobot |= 2;
102 antiRobotGo();
103 document.body.onmousedown=null;
104 }
105 document.body.onmousemove=function(){
106 antiRobot |= 2;
107 antiRobotGo();
108 document.body.onmousemove=null;
109 }
110 setTimeout(function(){
111 antiRobot |= 1;
112 antiRobotGo();
113 }, 100)
114 antiRobotGo();
115 }
116 antiRobotDefense();
117 </script>
118 <!-- keywords: SQLITE_DETERMINISTIC SQLITE_DIRECTONLY SQLITE_INNOCUOUS SQLITE_RESULT_SUBTYPE SQLITE_SUBTYPE -->
119 <div class=nosearch>
120 <a href="../c3ref/intro.html"><h2>SQLite C Interface</h2></a>
121 <h2>Function Flags</h2>
122 </div>
123 <blockquote><pre>
124 #define SQLITE_DETERMINISTIC 0x000000800
125 #define SQLITE_DIRECTONLY 0x000080000
126 #define SQLITE_SUBTYPE 0x000100000
127 #define SQLITE_INNOCUOUS 0x000200000
128 #define SQLITE_RESULT_SUBTYPE 0x001000000
129 </pre></blockquote>
130 <p>
131 These constants may be ORed together with the
132 <a href="../c3ref/c_any.html">preferred text encoding</a> as the fourth argument
133 to <a href="../c3ref/create_function.html">sqlite3_create_function()</a>, <a href="../c3ref/create_function.html">sqlite3_create_function16()</a>, or
134 <a href="../c3ref/create_function.html">sqlite3_create_function_v2()</a>.</p>
135
136 <p><dl>
137 <a name="sqlitedeterministic"></a>
138 <dt>SQLITE_DETERMINISTIC</dt><dd>
139 The SQLITE_DETERMINISTIC flag means that the new function always gives
140 the same output when the input parameters are the same.
141 The <a href="../lang_corefunc.html#abs">abs() function</a> is deterministic, for example, but
142 <a href="../lang_corefunc.html#randomblob">randomblob()</a> is not. Functions must
143 be deterministic in order to be used in certain contexts such as
144 with the WHERE clause of <a href="../partialindex.html">partial indexes</a> or in <a href="../gencol.html">generated columns</a>.
145 SQLite might also optimize deterministic functions by factoring them
146 out of inner loops.
147 </dd></p>
148
149 <p><a name="sqlitedirectonly"></a>
150 <dt>SQLITE_DIRECTONLY</dt><dd>
151 The SQLITE_DIRECTONLY flag means that the function may only be invoked
152 from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
153 schema structures such as <a href="../lang_createtable.html#ckconst">CHECK constraints</a>, <a href="../lang_createtable.html#dfltval">DEFAULT clauses</a>,
154 <a href="../expridx.html">expression indexes</a>, <a href="../partialindex.html">partial indexes</a>, or <a href="../gencol.html">generated columns</a>.
155 <p>
156 The SQLITE_DIRECTONLY flag is recommended for any
157 <a href="../appfunc.html">application-defined SQL function</a>
158 that has side-effects or that could potentially leak sensitive information.
159 This will prevent attacks in which an application is tricked
160 into using a database file that has had its schema surreptitiously
161 modified to invoke the application-defined function in ways that are
162 harmful.
163 <p>
164 Some people say it is good practice to set SQLITE_DIRECTONLY on all
165 <a href="../appfunc.html">application-defined SQL functions</a>, regardless of whether or not they
166 are security sensitive, as doing so prevents those functions from being used
167 inside of the database schema, and thus ensures that the database
168 can be inspected and modified using generic tools (such as the <a href="../cli.html">CLI</a>)
169 that do not have access to the application-defined functions.
170 </dd></p>
171
172 <p><a name="sqliteinnocuous"></a>
173 <dt>SQLITE_INNOCUOUS</dt><dd>
174 The SQLITE_INNOCUOUS flag means that the function is unlikely
175 to cause problems even if misused. An innocuous function should have
176 no side effects and should not depend on any values other than its
177 input parameters. The <a href="../lang_corefunc.html#abs">abs() function</a> is an example of an
178 innocuous function.
179 The <a href="../lang_corefunc.html#load_extension">load_extension() SQL function</a> is not innocuous because of its
180 side effects.
181 <p> SQLITE_INNOCUOUS is similar to SQLITE_DETERMINISTIC, but is not
182 exactly the same. The <a href="../lang_corefunc.html#random">random() function</a> is an example of a
183 function that is innocuous but not deterministic.
184 <p>Some heightened security settings
185 (<a href="../c3ref/c_dbconfig_defensive.html#sqlitedbconfigtrustedschema">SQLITE_DBCONFIG_TRUSTED_SCHEMA</a> and <a href="../pragma.html#pragma_trusted_schema">PRAGMA trusted_schema=OFF</a>)
186 disable the use of SQL functions inside views and triggers and in
187 schema structures such as <a href="../lang_createtable.html#ckconst">CHECK constraints</a>, <a href="../lang_createtable.html#dfltval">DEFAULT clauses</a>,
188 <a href="../expridx.html">expression indexes</a>, <a href="../partialindex.html">partial indexes</a>, and <a href="../gencol.html">generated columns</a> unless
189 the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
190 are innocuous. Developers are advised to avoid using the
191 SQLITE_INNOCUOUS flag for application-defined functions unless the
192 function has been carefully audited and found to be free of potentially
193 security-adverse side-effects and information-leaks.
194 </dd></p>
195
196 <p><a name="sqlitesubtype"></a>
197 <dt>SQLITE_SUBTYPE</dt><dd>
198 The SQLITE_SUBTYPE flag indicates to SQLite that a function might call
199 <a href="../c3ref/value_subtype.html">sqlite3_value_subtype()</a> to inspect the sub-types of its arguments.
200 This flag instructs SQLite to omit some corner-case optimizations that
201 might disrupt the operation of the <a href="../c3ref/value_subtype.html">sqlite3_value_subtype()</a> function,
202 causing it to return zero rather than the correct subtype().
203 SQL functions that invokes <a href="../c3ref/value_subtype.html">sqlite3_value_subtype()</a> should have this
204 property. If the SQLITE_SUBTYPE property is omitted, then the return
205 value from <a href="../c3ref/value_subtype.html">sqlite3_value_subtype()</a> might sometimes be zero even though
206 a non-zero subtype was specified by the function argument expression.</p>
207
208 <p><a name="sqliteresultsubtype"></a>
209 <dt>SQLITE_RESULT_SUBTYPE</dt><dd>
210 The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
211 <a href="../c3ref/result_subtype.html">sqlite3_result_subtype()</a> to cause a sub-type to be associated with its
212 result.
213 Every function that invokes <a href="../c3ref/result_subtype.html">sqlite3_result_subtype()</a> should have this
214 property. If it does not, then the call to <a href="../c3ref/result_subtype.html">sqlite3_result_subtype()</a>
215 might become a no-op if the function is used as term in an
216 <a href="../expridx.html">expression index</a>. On the other hand, SQL functions that never invoke
217 <a href="../c3ref/result_subtype.html">sqlite3_result_subtype()</a> should avoid setting this property, as the
218 purpose of this property is to disable certain optimizations that are
219 incompatible with subtypes.
220 </dd>
221 </dl>
222 </p><p>See also lists of
223 <a href="../c3ref/objlist.html">Objects</a>,
224 <a href="../c3ref/constlist.html">Constants</a>, and
225 <a href="../c3ref/funclist.html">Functions</a>.</p>
226