⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 set_authorizer.html

📁 嵌入式数据库sqlite 3.5.9的文档
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>Compile-Time Authorization Callbacks</title><style type="text/css">body {    margin: auto;    font-family: "Verdana" "sans-serif";    padding: 8px 1%;}a { color: #45735f }a:visited { color: #734559 }.logo { position:absolute; margin:3px; }.tagline {  float:right;  text-align:right;  font-style:italic;  width:240px;  margin:12px;  margin-top:58px;}.toolbar {  font-variant: small-caps;  text-align: center;  line-height: 1.6em;  margin: 0;  padding:1px 8px;}.toolbar a { color: white; text-decoration: none; padding: 6px 12px; }.toolbar a:visited { color: white; }.toolbar a:hover { color: #80a796; background: white; }.content    { margin: 5%; }.content dt { font-weight:bold; }.content dd { margin-bottom: 25px; margin-left:20%; }.content ul { padding:0px; padding-left: 15px; margin:0px; }/* rounded corners */.se  { background: url(../images/se.png) 100% 100% no-repeat #80a796}.sw  { background: url(../images/sw.png) 0% 100% no-repeat }.ne  { background: url(../images/ne.png) 100% 0% no-repeat }.nw  { background: url(../images/nw.png) 0% 0% no-repeat }</style><meta http-equiv="content-type" content="text/html; charset=UTF-8">  </head><body><div><!-- container div to satisfy validator --><a href="../index.html"><img class="logo" src="../images/SQLite.gif" alt="SQLite Logo" border="0"></a><div><!-- IE hack to prevent disappearing logo--></div><div class="tagline">Small. Fast. Reliable.<br>Choose any three.</div><table width=100% style="clear:both"><tr><td>  <div class="se"><div class="sw"><div class="ne"><div class="nw">  <div class="toolbar">    <a href="../about.html">About</a>    <a href="../sitemap.html">Sitemap</a>    <a href="../docs.html">Documentation</a>    <a href="../download.html">Download</a>    <a href="../copyright.html">License</a>    <a href="../news.html">News</a>    <a href="http://www.sqlite.org/cvstrac/index">Developers</a>    <a href="../support.html">Support</a>  </div></div></div></div></div></td></tr></table>  <a href="intro.html"><h2>SQLite C Interface</h2></a><h2>Compile-Time Authorization Callbacks</h2><blockquote><pre>int sqlite3_set_authorizer(  sqlite3*,  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),  void *pUserData);</pre></blockquote><p>This routine registers a authorizer callback with a particular<a href="../c3ref/sqlite3.html">database connection</a>, supplied in the first argument.The authorizer callback is invoked as SQL statements are being compiledby <a href="../c3ref/prepare.html">sqlite3_prepare()</a> or its variants <a href="../c3ref/prepare.html">sqlite3_prepare_v2()</a>,<a href="../c3ref/prepare.html">sqlite3_prepare16()</a> and <a href="../c3ref/prepare.html">sqlite3_prepare16_v2()</a>.  At variouspoints during the compilation process, as logic is being createdto perform various actions, the authorizer callback is invoked tosee if those actions are allowed.  The authorizer callback shouldreturn <a href="../c3ref/c_abort.html">SQLITE_OK</a> to allow the action, <a href="../c3ref/c_deny.html">SQLITE_IGNORE</a> to disallow thespecific action but allow the SQL statement to continue to becompiled, or <a href="../c3ref/c_deny.html">SQLITE_DENY</a> to cause the entire SQL statement to berejected with an error.   If the authorizer callback returnsany value other than <a href="../c3ref/c_deny.html">SQLITE_IGNORE</a>, <a href="../c3ref/c_abort.html">SQLITE_OK</a>, or <a href="../c3ref/c_deny.html">SQLITE_DENY</a>then <a href="../c3ref/prepare.html">sqlite3_prepare_v2()</a> or equivalent call that triggeredthe authorizer will fail with an error message.</p><p>When the callback returns <a href="../c3ref/c_abort.html">SQLITE_OK</a>, that means the operationrequested is ok.  When the callback returns <a href="../c3ref/c_deny.html">SQLITE_DENY</a>, the<a href="../c3ref/prepare.html">sqlite3_prepare_v2()</a> or equivalent call that triggered theauthorizer will fail with an error message explaining thataccess is denied.  If the authorizer code is <a href="../c3ref/c_alter_table.html">SQLITE_READ</a>and the callback returns <a href="../c3ref/c_deny.html">SQLITE_IGNORE</a> then the<a href="../c3ref/stmt.html">prepared statement</a> statement is constructed to substitutea NULL value in place of the table column that would havebeen read if <a href="../c3ref/c_abort.html">SQLITE_OK</a> had been returned.  The <a href="../c3ref/c_deny.html">SQLITE_IGNORE</a>return can be used to deny an untrusted user access to individualcolumns of a table.</p><p>The first parameter to the authorizer callback is a copy ofthe third parameter to the sqlite3_set_authorizer() interface.The second parameter to the callback is an integer<a href="../c3ref/c_alter_table.html">action code</a> that specifies the particular actionto be authorized. The third through sixthparameters to the callback are zero-terminated strings that containadditional details about the action to be authorized.</p><p>An authorizer is used when <a href="../c3ref/prepare.html">preparing</a>SQL statements from an untrustedsource, to ensure that the SQL statements do not try to access datathat they are not allowed to see, or that they do not try toexecute malicious statements that damage the database.  Forexample, an application may allow a user to enter arbitrarySQL queries for evaluation by a database.  But the application doesnot want the user to be able to make arbitrary changes to thedatabase.  An authorizer could then be put in place while theuser-entered SQL is being <a href="../c3ref/prepare.html">prepared</a> thatdisallows everything except <a href="../lang_select.html">SELECT</a> statements.</p><p>Applications that need to process SQL from untrusted sourcesmight also consider lowering resource limits using <a href="../c3ref/limit.html">sqlite3_limit()</a>and limiting database size using the <a href="../pragma.html#pragma_max_page_count">max_page_count</a> <a href="../pragma.html#syntax">PRAGMA</a>in addition to using an authorizer.</p><p>Only a single authorizer can be in place on a database connectionat a time.  Each call to sqlite3_set_authorizer overrides theprevious call.  Disable the authorizer by installing a NULL callback.The authorizer is disabled by default.</p><p>Note that the authorizer callback is invoked only during<a href="../c3ref/prepare.html">sqlite3_prepare()</a> or its variants.  Authorization is notperformed during statement evaluation in <a href="../c3ref/step.html">sqlite3_step()</a>.</p><p><h3>Invariants:</h3><table border="0" cellpadding="5" cellspacing="0"><tr><td valign="top">F12501</td> <td valign="top">The <a href="../c3ref/set_authorizer.html">sqlite3_set_authorizer(D,...)</a> interface registers aauthorizer callback with database connection D.</td></tr><tr><td valign="top">F12502</td> <td valign="top">The authorizer callback is invoked as SQL statements arebeing compiled</td></tr><tr><td valign="top">F12503</td> <td valign="top">If the authorizer callback returns any value other than<a href="../c3ref/c_deny.html">SQLITE_IGNORE</a>, <a href="../c3ref/c_abort.html">SQLITE_OK</a>, or <a href="../c3ref/c_deny.html">SQLITE_DENY</a> thenthe <a href="../c3ref/prepare.html">sqlite3_prepare_v2()</a> or equivalent call that causedthe authorizer callback to run shall fail with an<a href="../c3ref/c_abort.html">SQLITE_ERROR</a> error code and an appropriate error message.</td></tr><tr><td valign="top">F12504</td> <td valign="top">When the authorizer callback returns <a href="../c3ref/c_abort.html">SQLITE_OK</a>, the operationdescribed is coded normally.</td></tr><tr><td valign="top">F12505</td> <td valign="top">When the authorizer callback returns <a href="../c3ref/c_deny.html">SQLITE_DENY</a>, the<a href="../c3ref/prepare.html">sqlite3_prepare_v2()</a> or equivalent call that caused theauthorizer callback to run shall failwith an <a href="../c3ref/c_abort.html">SQLITE_ERROR</a> error code and an error messageexplaining that access is denied.</td></tr><tr><td valign="top">F12506</td> <td valign="top">If the authorizer code (the 2nd parameter to the authorizercallback) is <a href="../c3ref/c_alter_table.html">SQLITE_READ</a> and the authorizer callback returns<a href="../c3ref/c_deny.html">SQLITE_IGNORE</a> then the prepared statement is constructed toinsert a NULL value in place of the table column that would havebeen read if <a href="../c3ref/c_abort.html">SQLITE_OK</a> had been returned.</td></tr><tr><td valign="top">F12507</td> <td valign="top">If the authorizer code (the 2nd parameter to the authorizercallback) is anything other than <a href="../c3ref/c_alter_table.html">SQLITE_READ</a>, thena return of <a href="../c3ref/c_deny.html">SQLITE_IGNORE</a> has the same effect as <a href="../c3ref/c_deny.html">SQLITE_DENY</a>.</td></tr><tr><td valign="top">F12510</td> <td valign="top">The first parameter to the authorizer callback is a copy ofthe third parameter to the <a href="../c3ref/set_authorizer.html">sqlite3_set_authorizer()</a> interface.</td></tr><tr><td valign="top">F12511</td> <td valign="top">The second parameter to the callback is an integer<a href="../c3ref/c_alter_table.html">action code</a> that specifies the particular actionto be authorized.</td></tr><tr><td valign="top">F12512</td> <td valign="top">The third through sixth parameters to the callback arezero-terminated strings that containadditional details about the action to be authorized.</td></tr><tr><td valign="top">F12520</td> <td valign="top">Each call to <a href="../c3ref/set_authorizer.html">sqlite3_set_authorizer()</a> overrides theany previously installed authorizer.</td></tr><tr><td valign="top">F12521</td> <td valign="top">A NULL authorizer means that no authorizationcallback is invoked.</td></tr><tr><td valign="top">F12522</td> <td valign="top">The default authorizer is NULL.</td></tr></table></p><p>See also lists of  <a href="objlist.html">Objects</a>,  <a href="constlist.html">Constants</a>, and  <a href="funclist.html">Functions</a>.</p><hr><small><i>This page last modified 2008/05/12 13:08:44 UTC</i></small></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -