Browse Source

+ only set parameters when needed
+ Fix for null-values in date/time-fields

git-svn-id: trunk@1710 -

joost 20 years ago
parent
commit
3a226cbcc7
1 changed files with 17 additions and 7 deletions
  1. 17 7
      fcl/db/sqldb/odbc/odbcconn.pas

+ 17 - 7
fcl/db/sqldb/odbc/odbcconn.pas

@@ -332,6 +332,7 @@ var
 begin
   for i:=0 to High(ODBCCursor.FParamBuf) do
     FreeMem(ODBCCursor.FParamBuf[i]);
+  SetLength(ODBCCursor.FParamBuf,0);
 end;
 
 function TODBCConnection.GetHandle: pointer;
@@ -490,7 +491,7 @@ begin
   ODBCCursor:=cursor as TODBCCursor;
 
   // set parameters
-  SetParameters(ODBCCursor, AParams);
+    if Assigned(APArams) and (AParams.count > 0) then SetParameters(ODBCCursor, AParams);
 
   // execute the statement
   ODBCCheckResult(
@@ -547,20 +548,29 @@ begin
     ftTime:               // mapped to TTimeField
     begin
       Res:=SQLGetData(ODBCCursor.FSTMTHandle, FieldDef.Index+1, SQL_C_TYPE_TIME, @ODBCTimeStruct, SizeOf(SQL_TIME_STRUCT), @StrLenOrInd);
-      DateTime:=TimeStructToDateTime(@ODBCTimeStruct);
-      Move(DateTime, buffer^, SizeOf(TDateTime));
+      if StrLenOrInd<>SQL_NULL_DATA then
+      begin
+        DateTime:=TimeStructToDateTime(@ODBCTimeStruct);
+        Move(DateTime, buffer^, SizeOf(TDateTime));
+      end;
     end;
     ftDate:               // mapped to TDateField
     begin
       Res:=SQLGetData(ODBCCursor.FSTMTHandle, FieldDef.Index+1, SQL_C_TYPE_DATE, @ODBCDateStruct, SizeOf(SQL_DATE_STRUCT), @StrLenOrInd);
-      DateTime:=DateStructToDateTime(@ODBCDateStruct);
-      Move(DateTime, buffer^, SizeOf(TDateTime));
+      if StrLenOrInd<>SQL_NULL_DATA then
+      begin
+        DateTime:=DateStructToDateTime(@ODBCDateStruct);
+        Move(DateTime, buffer^, SizeOf(TDateTime));
+      end;
     end;
     ftDateTime:           // mapped to TDateTimeField
     begin
       Res:=SQLGetData(ODBCCursor.FSTMTHandle, FieldDef.Index+1, SQL_C_TYPE_TIMESTAMP, @ODBCTimeStampStruct, SizeOf(SQL_TIMESTAMP_STRUCT), @StrLenOrInd);
-      DateTime:=TimeStampStructToDateTime(@ODBCTimeStampStruct);
-      Move(DateTime, buffer^, SizeOf(TDateTime));
+      if StrLenOrInd<>SQL_NULL_DATA then
+      begin
+        DateTime:=TimeStampStructToDateTime(@ODBCTimeStampStruct);
+        Move(DateTime, buffer^, SizeOf(TDateTime));
+      end;
     end;
     ftBoolean:            // mapped to TBooleanField
       Res:=SQLGetData(ODBCCursor.FSTMTHandle, FieldDef.Index+1, SQL_C_BIT, buffer, SizeOf(Wordbool), @StrLenOrInd);