[PHPLIB-DEV] cvs commit From: negro (phplib-dev <email protected>)
Date: 11/11/99

From: negro
Date: Thu Nov 11 13:41:28 1999
Added files:
      php-lib/php/ct_sql_blob.inc

Modified files:
      php-lib/CHANGES
      php-lib/php/be_null.inc
      php-lib/php/be_sql.inc

Log message:
Checked in a draft implementation of ct_sql_blob, a container
using blob storage engine as proposed by Sascha and implemented
by me some time ago.

Some modifications to blob engine scheme, ripped out open and
close methods, renamed all methods without the blob_ prefix.

Please please please, give some feedback.

Index: php-lib/CHANGES
diff -u php-lib/CHANGES:1.145 php-lib/CHANGES:1.146
--- php-lib/CHANGES:1.145 Thu Nov 11 07:14:51 1999
+++ php-lib/CHANGES Thu Nov 11 13:40:56 1999
@@ -1,4 +1,12 @@
-$Id: CHANGES,v 1.145 1999/11/11 06:14:51 athompso Exp $
+$Id: CHANGES,v 1.146 1999/11/11 12:40:56 negro Exp $
+
+11-Nov-1999 negro
+ - Checked in a draft implementation of ct_sql_blob, a container
+ using blob storage engine as proposed by Sascha and implemented
+ by me some time ago.
+ - Some modifications to blob engine scheme, ripped out open and
+ close methods, renamed all methods without the blob_ prefix.
+ - Please please please, give some feedback.
 
 11-Nov-1999 ant
   - fixed more "unset variable" warnings for the paranoid among us,
Index: php-lib/php/be_null.inc
diff -u php-lib/php/be_null.inc:1.1 php-lib/php/be_null.inc:1.2
--- php-lib/php/be_null.inc:1.1 Thu Jul 22 15:44:27 1999
+++ php-lib/php/be_null.inc Thu Nov 11 13:40:57 1999
@@ -1,10 +1,9 @@
 <?php
-
 ##
 ## Copyright (c) 1999 Internet Images srl
 ## Massimiliano Masserelli <negro <email protected>>
 ##
-## $Id: be_null.inc,v 1.1 1999/07/22 13:44:27 negro Exp $
+## $Id: be_null.inc,v 1.2 1999/11/11 12:40:57 negro Exp $
 ##
 ## PHPLIB Blob Engine using nothing
 ##
@@ -15,31 +14,28 @@
 
 
 class BE_Null {
- function blob_create() {
- return false;
- }
-
- function blob_open($id) {
- return false;
- }
 
- function blob_close($id) {
- return false;
+ ## Create a new blob. Return the new blob_id on success.
+ function create() {
+ return false;
     }
 
- function blob_delete($id) {
+ ## Get rid of an existing blob. Return true on success.
+ function delete($id) {
         return false;
     }
 
- function blob_read($id) {
+ ## Read an existing blob. Return blob data on success.
+ function read($id) {
         return false;
     }
 
- function blob_write($id, $data) {
+ ## Write data to an existing blob. Return true on success.
+ function write($id, $data) {
         return false;
     }
-
 
+ ## Internal use, may come handy for error reporting.
     function halt($s) {
         echo "<b>$s</b>";
         exit;
Index: php-lib/php/be_sql.inc
diff -u php-lib/php/be_sql.inc:1.1 php-lib/php/be_sql.inc:1.2
--- php-lib/php/be_sql.inc:1.1 Thu Jul 22 15:44:27 1999
+++ php-lib/php/be_sql.inc Thu Nov 11 13:40:57 1999
@@ -1,130 +1,89 @@
 <?php
-
 ##
 ## Copyright (c) 1999 Internet Images srl
 ## Massimiliano Masserelli <negro <email protected>>
 ##
-## $Id: be_sql.inc,v 1.1 1999/07/22 13:44:27 negro Exp $
+## $Id: be_sql.inc,v 1.2 1999/11/11 12:40:57 negro Exp $
 ##
 ## PHPLIB Blob Engine using plain sql
 ## depends on db_sql
 ##
-## This is a "reference" class to be used only as an example. This should
-## not be used in applications.
-##
-## It's also a good skeleton for writing a new Blob Engine
-##
 ## The table used by this class must contain three fields:
-## be_bid 16 chars
-## be_seq 6 chars
-## be_data 4096 chars
+## be_bid 16 chars
+## be_seq 6 chars
+## be_data 2048 chars
 
 
 class BE_Sql {
- ##
- ## Define following parameters by overwriting or by deriving
- ## your own class (recommended)
- ##
- var $database_class = "DB_Sql"; ## access table via this class
- var $database_table = "be_table"; ## write data into this table
- var $split_length = 4096; ## maximum amount of data for each row
- ## this value should be safe enough
- ## end of configuration
-
- var $db; ## Internal, object used for db connection
-
- function start() {
- $name = $this->database_class;
- $this->db = new $name;
- }
-
- function blob_create() {
- if (! is_object($this->db)) {
- $this->start();
- }
- $bn = false;
- $count = 0;
- while (! $bn && ($count++ < 10)) {
- $bn = uniqid("");
- $this->db->query(sprintf("INSERT INTO %s".
- " (be_bid, be_seq, be_data) ".
- " VALUES ".
- " ('%s', '%06d', '')", $this->database_table, $bn, 0));
- if ($this->db->affected_rows() != 1) {
- $bn = "";
- }
- }
- return $bn;
- }
-
- function blob_open($id) {
- if (! is_object($this->db)) {
- $this->start();
- }
- $this->db->query("SELECT count(*) FROM ". $this->database_table.
- " WHERE be_bid = '$id'");
- if ($this->db->next_record()) {
- return ($this->db->f(0) > 0);
- } else {
- return false;
- }
- }
-
- function blob_close($id) {
- return true;
- }
-
- function blob_delete($id) {
- if (! is_object($this->db)) {
- $this->start();
- }
- $this->db->query("DELETE FROM ". $this->database_table.
- " WHERE be_bid = '$id'");
- return true;
- }
-
- function blob_read($id) {
- if (! is_object($this->db)) {
- $this->start();
- }
- $str = "";
- $this->db->query("SELECT be_data, be_seq FROM ". $this->database_table.
- " WHERE be_bid = '$id' ORDER BY be_seq");
- while ($this->db->next_record()) {
- $str .= $this->db->f(0);
- }
- return base64_decode($str);
- }
-
- function blob_write($id, $data) {
- if (! is_object($this->db)) {
- $this->start();
- }
- $this->db->query("BEGIN TRANSACTION");
- $this->db->query("DELETE FROM ". $this->database_table.
- " WHERE be_bid = '$id'");
- $str = base64_encode($data);
- $seq = 0;
- while ($part = substr($str, 0, $this->split_length)) {
- $this->db->query(sprintf("INSERT INTO %s ".
- "(be_bid, be_seq, be_data) ".
- " VALUES ".
- "('%s', '%06d', '%s')",
- $this->database_table,
- $id,
- $seq++,
- $part));
- $str = substr($str, $this->split_length);
- }
- $this->db->query("END TRANSACTION");
- return true;
- }
-
-
-## function halt($s) {
-## echo "<b>$s</b>";
-## exit;
-## }
+ ##
+ ## Define following parameters by overwriting or by deriving
+ ## your own class (recommended)
+ ##
+ var $database_class = "DB_Sql"; ## access table via this class
+ var $database_table = "be_table"; ## write data into this table
+ var $split_length = 2048; ## maximum amount of data for each row
+ ## this value should be safe enough
+ ## end of configuration
+
+ var $db; ## Internal, object used for db connection
+
+ function BE_Sql() {
+ $name = $this->database_class;
+ $this->db = new $name;
+ }
+
+ function create() {
+ $bn = false;
+ $count = 0;
+ while (! $bn && ($count++ < 10)) {
+ $bn = uniqid("");
+ $this->db->query(sprintf("INSERT INTO %s".
+ " (be_bid, be_seq, be_data) ".
+ " VALUES ".
+ " ('%s', '%06d', '')", $this->database_table, $bn, 0));
+ if ($this->db->affected_rows() != 1) {
+ $bn = "";
+ }
+ }
+ return $bn;
+ }
+
+ function delete($id) {
+ $this->db->query("DELETE FROM ". $this->database_table.
+ " WHERE be_bid = '$id'");
+ return true;
+ }
+
+ function read($id) {
+ $str = "";
+ $this->db->query("SELECT be_data, be_seq FROM ". $this->database_table.
+ " WHERE be_bid = '$id' ORDER BY be_seq");
+ while ($this->db->next_record()) {
+ $str .= $this->db->f(0);
+ }
+ return base64_decode($str);
+ }
+
+ function write($id, $data) {
+ $this->db->query("BEGIN TRANSACTION");
+ $this->db->query("DELETE FROM ". $this->database_table.
+ " WHERE be_bid = '$id'");
+ $str = base64_encode($data);
+ $seq = 0;
+ while ($part = substr($str, 0, $this->split_length)) {
+ $this->db->query(sprintf("INSERT INTO %s ".
+ "(be_bid, be_seq, be_data) ".
+ " VALUES ".
+ "('%s', '%06d', '%s')",
+ $this->database_table,
+ $id,
+ $seq++,
+ $part));
+ $str = substr($str, $this->split_length);
+ }
+ $this->db->query("END TRANSACTION");
+ return true;
+ }
 
 }
 ?>

-
PHPLIB Developers Mailing List. Send messages to <phplib-dev <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-dev-request <email protected>> in
the body, not the subject, of your message.