Browse Source

Merged revisions 7881,7901,7923 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r7881 | joost | 2007-06-30 23:54:27 +0200 (Sat, 30 Jun 2007) | 1 line

* Fix ftString parameters for blob-fields
........
r7901 | joost | 2007-07-01 13:32:13 +0200 (Sun, 01 Jul 2007) | 1 line

* Support ftMemo parameters
........
r7923 | joost | 2007-07-02 22:35:38 +0200 (Mon, 02 Jul 2007) | 1 line

* Patch from Luiz Americo to let Tsqlite*Dataset.Applyupdate return false if any error occured. (mantis 9123)
........

git-svn-id: branches/fixes_2_2@7994 -

joost 18 years ago
parent
commit
40d77aad88

+ 36 - 25
packages/fcl-db/src/sqldb/interbase/ibconnection.pp

@@ -679,6 +679,39 @@ var ParNr,SQLVarNr : integer;
     blobHandle        : Isc_blob_Handle;
     BlobSize,
     BlobBytesWritten  : longint;
+    
+  procedure SetBlobParam;
+  
+  begin
+{$R-}
+    with cursor as TIBCursor do
+      begin
+      TransactionHandle := transaction.Handle;
+      blobhandle := nil;
+      if isc_create_blob(@FStatus[0], @FSQLDatabaseHandle, @TransactionHandle, @blobHandle, @blobId) <> 0 then
+       CheckError('TIBConnection.CreateBlobStream', FStatus);
+
+      s := AParams[ParNr].AsString;
+      BlobSize := length(s);
+
+      BlobBytesWritten := 0;
+      i := 0;
+
+      while BlobBytesWritten < (BlobSize-BlobSegmentSize) do
+        begin
+        isc_put_segment(@FStatus[0], @blobHandle, BlobSegmentSize, @s[(i*BlobSegmentSize)+1]);
+        inc(BlobBytesWritten,BlobSegmentSize);
+        inc(i);
+        end;
+      if BlobBytesWritten <> BlobSize then
+        isc_put_segment(@FStatus[0], @blobHandle, BlobSize-BlobBytesWritten, @s[(i*BlobSegmentSize)+1]);
+
+      if isc_close_blob(@FStatus[0], @blobHandle) <> 0 then
+        CheckError('TIBConnection.CreateBlobStream isc_close_blob', FStatus);
+      Move(blobId, in_sqlda^.SQLvar[SQLVarNr].SQLData^, in_SQLDA^.SQLVar[SQLVarNr].SQLLen);
+      end;
+{$R+}
+  end;
 
 begin
 {$R-}
@@ -700,7 +733,7 @@ begin
           i := AParams[ParNr].AsInteger;
           Move(i, in_sqlda^.SQLvar[SQLVarNr].SQLData^, in_SQLDA^.SQLVar[SQLVarNr].SQLLen);
           end;
-        ftString,ftFixedChar  :
+        ftString,ftFixedChar  : if ((in_sqlda^.SQLvar[SQLVarNr].SQLType and not 1) = SQL_BLOB) then SetBlobParam else
           begin
           s := AParams[ParNr].AsString;
           w := length(s); // a word is enough, since the max-length of a string in interbase is 32k
@@ -726,31 +759,9 @@ begin
           end;
         ftFloat:
           SetFloat(in_sqlda^.SQLvar[SQLVarNr].SQLData, AParams[ParNr].AsFloat, in_SQLDA^.SQLVar[SQLVarNr].SQLLen);
-        ftBlob:
+        ftBlob, ftMemo:
           begin
-          TransactionHandle := transaction.Handle;
-          blobhandle := nil;
-          if isc_create_blob(@FStatus[0], @FSQLDatabaseHandle, @TransactionHandle, @blobHandle, @blobId) <> 0 then
-           CheckError('TIBConnection.CreateBlobStream', FStatus);
-
-          s := AParams[ParNr].AsString;
-          BlobSize := length(s);
-
-          BlobBytesWritten := 0;
-          i := 0;
-
-          while BlobBytesWritten < (BlobSize-BlobSegmentSize) do
-            begin
-            isc_put_segment(@FStatus[0], @blobHandle, BlobSegmentSize, @s[(i*BlobSegmentSize)+1]);
-            inc(BlobBytesWritten,BlobSegmentSize);
-            inc(i);
-            end;
-          if BlobBytesWritten <> BlobSize then
-            isc_put_segment(@FStatus[0], @blobHandle, BlobSize-BlobBytesWritten, @s[(i*BlobSegmentSize)+1]);
-            
-          if isc_close_blob(@FStatus[0], @blobHandle) <> 0 then
-            CheckError('TIBConnection.CreateBlobStream isc_close_blob', FStatus);
-          Move(blobId, in_sqlda^.SQLvar[SQLVarNr].SQLData^, in_SQLDA^.SQLVar[SQLVarNr].SQLLen);
+          SetBlobParam;
           end;
       else
         DatabaseErrorFmt(SUnsupportedParameter,[Fieldtypenames[AParams[ParNr].DataType]],self);

+ 14 - 5
packages/fcl-db/src/sqlite/customsqliteds.pas

@@ -1251,7 +1251,7 @@ end;
 
 function TCustomSqliteDataset.ApplyUpdates:Boolean;
 var
-  iFields,iItems,StatementsCounter:Integer;
+  iFields, iItems, StatementsCounter, TempReturnCode:Integer;
   SqlTemp,WhereKeyNameEqual,ASqlLine,TemplateStr:String;
   TempItem: PDataRecord;
 begin
@@ -1264,6 +1264,7 @@ begin
   Result:=False;
   if FPrimaryKeyNo <> -1 then
   begin
+    FReturnCode := SQLITE_OK;
     StatementsCounter:=0;
     WhereKeyNameEqual:=' WHERE '+Fields[FPrimaryKeyNo].FieldName+' = ';
     {$ifdef DEBUG_SQLITEDS}
@@ -1288,7 +1289,9 @@ begin
       if StatementsCounter = 400 then
       begin
         SqlTemp:=SqlTemp+'COMMIT;';
-        FReturnCode:=SqliteExec(PChar(SqlTemp),nil,nil);
+        TempReturnCode := SqliteExec(PChar(SqlTemp),nil,nil);
+        if TempReturnCode <> SQLITE_OK then
+          FReturnCode := TempReturnCode;  
         StatementsCounter:=0;
         SqlTemp:='BEGIN;';
       end;    
@@ -1314,7 +1317,9 @@ begin
       if StatementsCounter = 400 then
       begin
         SqlTemp:=SqlTemp+'COMMIT;';
-        FReturnCode:=SqliteExec(PChar(SqlTemp),nil,nil);
+        TempReturnCode := SqliteExec(PChar(SqlTemp),nil,nil);
+        if TempReturnCode <> SQLITE_OK then
+          FReturnCode := TempReturnCode;
         StatementsCounter:=0;
         SqlTemp:='BEGIN;';
       end;  
@@ -1344,7 +1349,9 @@ begin
       if StatementsCounter = 400 then
       begin
         SqlTemp:=SqlTemp+'COMMIT;';
-        FReturnCode:=SqliteExec(PChar(SqlTemp),nil,nil);
+        TempReturnCode := SqliteExec(PChar(SqlTemp),nil,nil);
+        if TempReturnCode <> SQLITE_OK then
+          FReturnCode := TempReturnCode;
         StatementsCounter:=0;
         SqlTemp:='BEGIN;';
       end;  
@@ -1356,7 +1363,9 @@ begin
    FAddedItems.Clear;
    FUpdatedItems.Clear;
    FDeletedItems.Clear;   
-   FReturnCode:=SqliteExec(PChar(SqlTemp),nil,nil);
+   TempReturnCode := SqliteExec(PChar(SqlTemp),nil,nil);
+   if TempReturnCode <> SQLITE_OK then
+     FReturnCode := TempReturnCode;
    Result:= FReturnCode = SQLITE_OK;
   end;  
   {$ifdef DEBUG_SQLITEDS}