Hi!

While fixing some other stuff (patches for which I'll submit when I
get around to it), I really wanted to use bind parameters for select
statements as well as for inserts and deletes.  So I just copied to
approach used in Do().

I also removed LongTruncOK=0 and set LongReadLen to the same as the
MaxFileUpload config setting.  With the original settings, everything
but the smallest attachments would be truncated on their way out of
the database.

--- ../../../../otrs-cvs/otrs-rel-1_3-2004-12-16/Kernel/System/DB.pm	2004-08-12 10:10:17.000000000 +0200
+++ Kernel/System/DB.pm	2004-12-15 14:55:26.000000000 +0100
@@ -150,8 +150,8 @@
         $Self->{'DB::QuoteBack'} = 0;
         $Self->{'DB::QuoteSemicolon'} = '';
         $Self->{'DB::Attribute'} = {
-            LongTruncOk => 1,
-            LongReadLen => 100*1024,
+            LongTruncOk => 0,
+            LongReadLen => $Self->{ConfigObject}->Get('MaxFileUpload'),
         };
     }
     elsif ($Self->{'DB::Type'} eq 'db2') {
@@ -394,6 +394,17 @@
       Limit => 10
   );
 
+  you also can use DBI bind values:
+
+  my $Var1 = 'dog1';
+  my $Var2 = 'dog2';
+
+  $DBObject->Do(
+      SQL => "SELECT * FROM table WHERE id = ?",
+      Bind => [\$Var1],
+  );
+
+
 =cut
 
 sub Prepare {
@@ -401,6 +412,8 @@
     my %Param = @_;
     my $SQL = $Param{SQL};
     my $Limit = $Param{Limit} || '';
+    my @Bindparams = ();
+
     $Self->{Limit} = 0;
     $Self->{LimitCounter} = 0;
     # build finally select query
@@ -424,6 +437,22 @@
           Message => "DB.pm->Prepare ($Self->{PrepareCounter}/".time().") SQL: '$SQL'",
         );
     }
+    # bind
+    if ($Param{Bind}) {
+	foreach my $Data (@{$Param{Bind}}) {
+	    if (ref($Data) eq 'SCALAR') {
+                push(@Bindparams, $$Data);
+            }
+            else  {
+                $Self->{LogObject}->Log(
+                    Caller => 1,
+                    Priority => 'Error',
+   		    Message => "No SCALAR param in Bind: " . ref($Data) . "!",
+                );
+                return;
+            }
+	}
+    }
     # do
     if (!($Self->{Curser} = $Self->{dbh}->prepare($SQL))) {
         $Self->{LogObject}->Log(
@@ -433,7 +462,15 @@
         );
         return;
     }
-    if (!$Self->{Curser}->execute()) {
+    # execute
+    
+    # It seems DBI really doesn't like a bind parameter array (even an
+    # empty one) if it doesn't have bind parameters to bind them to.
+    # Oh well...
+    my $executed = ( scalar(@Bindparams) > 0
+		     ? $Self->{Curser}->execute(@Bindparams)
+		     : $Self->{Curser}->execute() );
+    if (!$executed) {
         $Self->{LogObject}->Log(
           Caller => 1,
           Priority => 'Error',
Regards,
-- 
Kristoffer.
_______________________________________________
OTRS mailing list: dev - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/dev
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/dev

Reply via email to