Re: Enable authorizer-feature in PDO_SQLITE
| From: | Wez Furlong | Date: | Thu, 16 Nov 2006 16:40:00 +0000 |
| Subject: | Re: Enable authorizer-feature in PDO_SQLITE | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-26646@lists.php.net to get a copy of this message | ||
I think it would be better to pass in the pdo_dbh_t as the autharg to
the C level callback and then use that to determine if any of the
expensive work needs to be done in the callback.
static int authorizer(....)
{
pdo_dbh_t *db;
/* keep the current safemode / basedir checks "cheap" and fast */
if (existing safe_mode and open_base dir return SQLITE_DENY) {
return SQLITE_DENY;
}
db = (pdo_dbh_t*)autharg;
if (db->user_authorizer) {
TSRMLS_FETCH();
...
free stuff
}
}
You should take a look at how the pdo_sqlite_fci stuff works and adopt
that for the authorizer callback, as it will help improve runtime
performance there.
It would also be best to register constants for the various SQLITE_XXX codes
rather than creating strings and having the PHP code check against strings.
This will also improve performance at runtime.
--Wez.
On 11/16/06, Mario Wolff <wolfshoehle@googlemail.com> wrote:
Short test script: <?php $data = array( 'one', 'two', 'three', 'four', 'five', 'six'); $db = new PDO( 'sqlite::memory:'); echo "register authorizer\n"; $db->sqliteSetAuthorizer('auth'); $db->exec( "CREATE TABLE strings( a)"); $insert = $db->prepare( 'INSERT INTO strings VALUES ( ?)'); foreach ( $data as $str) {$insert->execute( array( $str));} $insert = null; echo "unregister authorizer\n"; $db->sqliteSetAuthorizer(); function auth($type,$arga,$argb,$argc,$argd ){echo "$type\t$arga\t$argb\t$argc\t$argd\n"; return true;} print_r( $db->query( 'SELECT sqlite_version( *);')->fetchAll( )); ?> gives: register authorizerSQLITE_INSERT sqlite_master main SQLITE_CREATE_TABLE strings main SQLITE_UPDATE sqlite_master type main SQLITE_UPDATE sqlite_master name main SQLITE_UPDATE sqlite_master tbl_name main SQLITE_UPDATE sqlite_master rootpage main SQLITE_UPDATE sqlite_master sql main SQLITE_READ sqlite_master ROWID main SQLITE_READ sqlite_master name main SQLITE_READ sqlite_master rootpage main SQLITE_READ sqlite_master sql main SQLITE_READ sqlite_master tbl_name main SQLITE_INSERT strings mainunregister authorizer Array ([0] => Array ( [sqlite_version( *)] => 3.3.7 [0] => 3.3.7 ))