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

From: kir
Date: Thu Nov 4 13:02:09 1999
Modified files:
      php-lib/CHANGES
      php-lib/php/ct_split_sql.inc
      php-lib/php/ct_sql.inc

Log message:

  Remake ct_split_sql.inc ala ct_sql.inc.
  Oracle transaction support for ct_split_sql.inc
  Better compatibility for ct_sql.inc

Index: php-lib/CHANGES
diff -u php-lib/CHANGES:1.136 php-lib/CHANGES:1.137
--- php-lib/CHANGES:1.136 Thu Nov 4 00:39:51 1999
+++ php-lib/CHANGES Thu Nov 4 13:02:07 1999
@@ -1,4 +1,14 @@
-$Id: CHANGES,v 1.136 1999/11/03 23:39:51 athompso Exp $
+$Id: CHANGES,v 1.137 1999/11/04 12:02:07 kir Exp $
+
+03-Nov-1999 kir
+ - more compatibility for ct_sql.inc
+ - make ct_split_sql.inc several enc. methods aware ala ct_sql.inc
+ - Oracle transaction support for ct_split_sql.inc
+
+03-Nov-1999 ant
+ - fixed kk's notion of what month it is...
+ - added a check in ct_sql.inc to handle the compatibility case
+ where no encoding_mode can be determined
 
 03-Nov-1999 ant
   - fixed kk's notion of what month it is...
Index: php-lib/php/ct_split_sql.inc
diff -u php-lib/php/ct_split_sql.inc:1.2 php-lib/php/ct_split_sql.inc:1.3
--- php-lib/php/ct_split_sql.inc:1.2 Tue Oct 26 15:33:36 1999
+++ php-lib/php/ct_split_sql.inc Thu Nov 4 13:02:08 1999
@@ -3,7 +3,7 @@
 ## Copyright (c) 1999 Internet Images srl
 ## Massimiliano Masserelli
 ##
-## $Id: ct_split_sql.inc,v 1.2 1999/10/26 13:33:36 kir Exp $
+## $Id: ct_split_sql.inc,v 1.3 1999/11/04 12:02:08 kir Exp $
 ##
 ## PHPLIB Data Storage Container using a SQL database and multiple
 ## rows for each element
@@ -23,7 +23,11 @@
     var $database_lock_semaphore = "";
     var $split_length = 4096; ## Split data every xxx bytes
 
- ## The only supported storage method is base64 encoding
+ var $enc_methods = array(
+ "base64" => array("enc" => "base64_encode", "dec" => "base64_decode"),
+ "slashes" => array("enc" => "addslashes", "dec" => "stripslashes")
+ );
+ var $encoding_mode = "base64";
     ## end of configuration
 
     var $db;
@@ -61,10 +65,18 @@
 
     function ac_store($id, $name, $str) {
         $ret = true;
- $str = base64_encode($str);
+
+ $cmd = $this->enc_methods[$this->encoding_mode]["enc"];
+ $str = sprintf("%s:%s", $this->encoding_mode, $cmd($str));
+
         $now = date("YmdHis", time());
         
- $this->db->query("BEGIN TRANSACTION");
+ if ( $this->db->type == "oracle" )
+ {
+ Ora_CommitOff($this->db->Link_ID);
+ } else {
+ $this->db->query("BEGIN TRANSACTION");
+ }
         $this->ac_delete($id, $name);
         
         $count = 0;
@@ -82,7 +94,18 @@
             ));
             $str = substr($str, $this->split_length);
         }
- $this->db->query("END TRANSACTION");
+ if ( $this->db->type == "oracle" )
+ {
+ // Commit transaction
+ if(! <email protected>($this->db->Link_ID))
+ {
+ $ret = false;
+ }
+ // Enable autocommit again
+ Ora_CommitOn($this->db->Link_ID);
+ } else {
+ $this->db->query("END TRANSACTION");
+ }
         return $ret;
     }
 
@@ -104,10 +127,23 @@
         $str="";
         while ($this->db->next_record()) {
           $str .= $this->db->f("ct_val");
+ }
+
+ # get encoding method from (method:value) pair
+ $colon_pos = strpos($str,':');
+ $str_method = substr ( $str , 0 , $colon_pos );
+ if( empty($str_method) ) {
+ // For compatibility with old sessions
+ $str_method = "base64";
+ $str_value = $str;
+ } else {
+ // New format case
+ $str_value = substr ( $str , $colon_pos + 1 );
         }
- if (! empty($str)) {
- $str = base64_decode($str);
- };
+ $cmd = $this->enc_methods[$str_method]["dec"];
+
+ $str = $cmd($str_value);
+
 ## DEB echo $str;
         return $str;
     }
@@ -118,6 +154,17 @@
 
     function ac_halt($s) {
         $this->db->halt($s);
+ }
+
+ ## provide your own encoding/decoding method(s)
+ function set_enc_meth($name, $enc_func, $dec_func) {
+ if (!isset($this->enc_methods[$name])) {
+ $this->enc_methods[$name] = array ('enc'=> $enc_func, 'dec'=> $dec_func) ;
+ }
+ }
+
+ function get_enc_meth($name) {
+ return $this->enc_methods[$name];
     }
 }
 ?>
Index: php-lib/php/ct_sql.inc
diff -u php-lib/php/ct_sql.inc:1.17 php-lib/php/ct_sql.inc:1.18
--- php-lib/php/ct_sql.inc:1.17 Thu Nov 4 00:36:24 1999
+++ php-lib/php/ct_sql.inc Thu Nov 4 13:02:08 1999
@@ -6,7 +6,7 @@
 ##
 ## Copyright (c) 1998,1999 Sascha Schumann <sascha <email protected>>
 ##
-## $Id: ct_sql.inc,v 1.17 1999/11/03 23:36:24 athompso Exp $
+## $Id: ct_sql.inc,v 1.18 1999/11/04 12:02:08 kir Exp $
 ##
 ## PHPLIB Data Storage Container using a SQL database
 ##
@@ -116,16 +116,17 @@
       # get encoding method from (method:value) pair
       $colon_pos = strpos($str,':');
       $str_method = substr ( $str , 0 , $colon_pos );
- $str_value = substr ( $str , $colon_pos + 1 );
-
       if( empty($str_method) ) {
- $cmd = $this->enc_methods[$this->encoding_mode]["dec"];
+ // For compatibility with old sessions
+ $str_method = "base64";
+ $str_value = $str;
       } else {
- $cmd = $this->enc_methods[$str_method]["dec"];
- };
+ // New format case
+ $str_value = substr ( $str , $colon_pos + 1 );
+ }
+ $cmd = $this->enc_methods[$str_method]["dec"];
 
       $str = $cmd($str_value);
- }
 
     return $str;
   }

-
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.