Re: how to make nasty code less nasty (obtaining sqlite db handle)
| From: | Derrell dot Lipman at UnwiredUniverse dot com | Date: | Fri, 04 Feb 2005 03:56:04 +0000 |
| Subject: | Re: how to make nasty code less nasty (obtaining sqlite db handle) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-14636@lists.php.net to get a copy of this message | ||
Wez Furlong <kingwez@gmail.com> writes:
> There is no official way to do this kind of thing between arbitrary
> extensions. When extensions that are written to share this information,
> they typically export an XXX_API function that you can link against to fetch
> the data.
>
> What you've done works, so that's fine, although there is a risk of
> crashing if someone passes the wrong type of resource in. If you're
> thinking of distributing your extension, we could add a more official
> API for you to use, although that doesn't exist in older versions of
> the extension, etc. etc.
Thanks, Wez. My extension will likely never be used other than with
locally-written code. My biggest concern is making use of the incestual
knowledge of the private php_sqlite_db structure and that the database handle
is the first field in it. That structure may change in the future.
My use of this is as a function used in a query -- sqlite_create_function() is
used to allow a call to a php function which passes the database handle to the
extension function. Prior to today, my extension had its own private database
handle that it initialized on the MINIT function, but I was causing a deadlock
by calling this function from within a query in PHP which called the extension
which tried to issue additional queries using my private database handle in
the extension. Passing in the php-derived handle is the only way of
eliminating that deadlock.
I wonder whether I'm really alone in wanting access to a database handle for
extensions. It would seem appropriate to provide access to the C-level
database handle given a PHP resources. That would eliminate the need to base
an extenion on insestual knowledge of the database-specific extension.
Thanks again,
Derrell