Re: Enable authorizer-feature in PDO_SQLITE

From: Date: Fri, 17 Nov 2006 22:02:39 +0000
Subject: Re: Enable authorizer-feature in PDO_SQLITE
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-26664@lists.php.net to get a copy of this message
2006/11/16, Wez Furlong <kingwez@gmail.com>:
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.
Saves the sqlite_set_authorizer recall in SetAuthorizer, Looks simpler and cleaner. -> done
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();
What is this? I'm not familiar with the hole php-stuff, sorry! Done by:
+       pdo_dbh_t *dbh;
+       pdo_sqlite_db_handle *H;
...
+       dbh=(pdo_dbh_t*)autharg;
+       PDO_CONSTRUCT_CHECK;
+       H = (pdo_sqlite_db_handle *)dbh->driver_data;
+
+       if( H->user_authorizer ){
OK?
... 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.
Can't find usefull stuff to adopt. Can you hint me further?
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.
I like talking parameters! But you are right, performance comes first! -> done
Short test script: Modified:
<?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; if( $delete = $db->prepare( 'DELETE FROM strings where a=?')){ if( $delete->execute(array( "six" ))){
      echo "delete done!\n";
} $delete = null; }else{ echo "delete not prepared\n"; } echo "unregister authorizer\n"; $db->sqliteSetAuthorizer(); if( $delete = $db->prepare( 'DELETE FROM strings where a=?')){ if( $delete->execute(array( "six" ))){
      echo "delete done!\n";
} $delete = null; }else{ echo "delete not prepared\n"; } function auth($type,$arga,$argb,$argc,$argd ){ echo "$type\t$arga\t$argb\t$argc\t$argd\n"; if( $type==SQLITE_DELETE ){
      return SQLITE_DENY;
} return SQLITE_OK; } print_r( $db->query( 'SELECT sqlite_version( *);')->fetchAll( )); print_r( $db->query( 'SELECT * from strings;')->fetchAll( )); ?>
gives: now:
register authorizer
18      sqlite_master           main
2       strings         main
23      sqlite_master   type    main
23      sqlite_master   name    main
23      sqlite_master   tbl_name        main
23      sqlite_master   rootpage        main
23      sqlite_master   sql     main
20      sqlite_master   ROWID   main
20      sqlite_master   name    main
20      sqlite_master   rootpage        main
20      sqlite_master   sql     main
20      sqlite_master   tbl_name        main
18      strings         main
9       strings         main
delete not prepared unregister authorizer delete done! Array ( [0] => Array
      (
          [sqlite_version( *)] => 3.3.7
          [0] => 3.3.7
      )
) Array ( [0] => Array
      (
          [a] => one
          [0] => one
      )
[1] => Array
      (
          [a] => two
          [0] => two
      )
[2] => Array
      (
          [a] => three
          [0] => three
      )
[3] => Array
      (
          [a] => four
          [0] => four
      )
[4] => Array
      (
          [a] => five
          [0] => five
      )
) Regards, Mario

Attachment: [text/x-patch] pdo_sqlite.diff
« previous php.internals (#26664) next »