[development] DB support as contribute: is it a good idea?

Edison Wong hswong3i at edin.no-ip.com
Mon Feb 18 01:54:03 UTC 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 
Hmm... From my point of view, it is just similar as 
http://netevil.org/uuid/4365876a-cee9-3009-7726-365876a51802 (although 
it is target for pdo_oci, it share the same idea as pdo_pgsql):
<?php
$db = new PDO("oci:", "scott", "tiger");
$db->beginTransaction(); // Essential!
$stmt = $db->prepare(
~  "INSERT INTO blobtest (id, contenttype, blob) ".
~  "VALUES (:id, :type, EMPTY_BLOB()) ".
~  "RETURNING blob INTO :blob");
$stmt->bindParam(':id', $id);
$stmt->bindParam(':type', $type);
$stmt->bindParam(':blob', $blob, PDO::PARAM_LOB);
$type = 'image/gif';
$id = 1; // generate your own unique id here
$blob = fopen('/path/to/a/graphic.gif', 'rb');
$stmt->execute();
$stmt->commit();
?>

http://php.net/pdo#pdo.lobs also come with some example (BTW, this level 
of code snippet is TOTALLY NOT ENOUGH for a Drupal-style db_query() 
implementation...):
<?php
$db = new PDO('odbc:SAMPLE', 'db2inst1', 'ibmdb2');
$stmt = $db->prepare("insert into images (id, contenttype, imagedata) 
values (?, ?, ?)");
$id = get_new_id(); // some function to allocate a new ID

// assume that we are running as part of a file upload form
// You can find more information in the PHP documentation

$fp = fopen($_FILES['file']['tmp_name'], 'rb');

$stmt->bindParam(1, $id);
$stmt->bindParam(2, $_FILES['file']['type']);
$stmt->bindParam(3, $fp, PDO::PARAM_LOB);

$db->beginTransaction();
$stmt->execute();
$db->commit();
?>

On the other hand, I get a functional implementation of pdo_pgsql *done* 
with correct PDO + PostgreSQL BLOB handling, based on our existing D6 DB 
API with minimal amount of logic change:
http://edin.no-ip.com/viewvc/siren/includes/database.pdo_pgsql.inc?view=markup
http://edin.no-ip.com/viewvc/siren/includes/common.postgresql.inc?view=markup
http://edin.no-ip.com/viewvc/siren/includes/schema.postgresql.inc?view=markup
http://edin.no-ip.com/viewvc/siren/includes/install.postgresql.inc?view=markup

Like this one? Don't forget that they are parallel developed with 
pdo_mysql, pdo_oci, pdo_sqlite, and pdo_ibm, where all of the other are 
both function correctly. I am not trying to trigger a war of 
implementation; BTW, a tiny amount brain-storming-level code snippet 
(which similar implementation is all around the world...) is not enough 
for supporting a positive technical-based discussion ;-(

Karoly Negyesi wrote:
|> delegation (including asking Karoly to write pg drivers <g>)... but
|
| $db = new PDO('pgsql:dbname=drupal', 'drupal', 'drupal');
| $binarydata = "abcdefg\x00a\x00\x01\x02";
| $db->exec('CREATE TABLE test (data bytea, comment varchar(64), len 
integer)');
| $db->beginTransaction();
| $stmt = $db->prepare("INSERT INTO test (data, comment, len) VALUES 
(:data, :comment, :len)");
| $stmt->bindParam(':len', $len);
| $stmt->bindParam(':data', $blob, PDO::PARAM_LOB);
| $blob = fopen('php://memory', 'a');
| $len = fwrite($blob, $binarydata);
| rewind($blob);
| $comment = 'lob';
| $stmt->bindParam(':comment', $comment);
| $stmt->execute();
| $db->commit();
|
| Like that? I *did* write the skeleton of LOB handling for postgresql, 
mind ya.

- --
Edison Wong
hswong3i at gmail.com
http://edin.no-ip.com/html/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iD8DBQFHuOU7BPIQaq+ZRd8RAivRAKCW0wbmUokTo8nPl/21GONyJfNUzACfbOKg
WxdXzpYkBAsr4aRlsETOsk4=
=2jiO
-----END PGP SIGNATURE-----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080218/d7747ff6/attachment-0004.htm 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080218/d7747ff6/attachment-0005.htm 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080218/d7747ff6/attachment-0006.htm 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080218/d7747ff6/attachment-0007.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hswong3i.vcf
Type: text/x-vcard
Size: 187 bytes
Desc: not available
Url : http://lists.drupal.org/pipermail/development/attachments/20080218/d7747ff6/attachment-0001.vcf 


More information about the development mailing list