瀏覽代碼

fcl-db: mssql: add support for new MS SQL 2008 datetime data types. Depends on rev.27979 and requires new FreeTDS dblib library

git-svn-id: trunk@27981 -
lacak 11 年之前
父節點
當前提交
bafe66a3f0
共有 2 個文件被更改,包括 59 次插入29 次删除
  1. 30 13
      packages/fcl-db/src/sqldb/mssql/mssqlconn.pp
  2. 29 16
      packages/fcl-db/src/sqldb/mssql/readme.txt

+ 30 - 13
packages/fcl-db/src/sqldb/mssql/mssqlconn.pp

@@ -196,7 +196,7 @@ const
   SBeginTransaction = 'BEGIN TRANSACTION';
   SAutoCommit = 'AUTOCOMMIT';
   STextSize   = 'TEXTSIZE';
-  SAppName   = 'APPLICATIONNAME';
+  SAppName    = 'APPLICATIONNAME';
 
 
 var
@@ -669,10 +669,15 @@ begin
     SQLFLTN:             Result:=ftFloat;
     SQLMONEY4, SQLMONEY,
     SQLMONEYN:           Result:=ftCurrency;
+    SYBMSDATE:           Result:=ftDate;
+    SYBMSTIME:           Result:=ftTime;
     SQLDATETIM4, SQLDATETIME,
-    SQLDATETIMN:         Result:=ftDateTime;
-    SQLIMAGE:            Result:=ftBlob;
+    SQLDATETIMN,
+    SYBMSDATETIME2,
+    SYBMSDATETIMEOFFSET: Result:=ftDateTime;
+    SYBMSXML,
     SQLTEXT:             Result:=ftMemo;
+    SQLIMAGE:            Result:=ftBlob;
     SQLDECIMAL, SQLNUMERIC: Result:=ftBCD;
     SQLBIT:              Result:=ftBoolean;
     SQLBINARY:           Result:=ftBytes;
@@ -753,8 +758,8 @@ var i: integer;
     srctype, desttype: INT;
     dbdt: DBDATETIME;
     dbdr: DBDATEREC;
+    dbdta: DBDATETIMEALL;
     bcdstr: array[0..MaxFmtBCDFractionSize+2] of char;
-    f: double;
 begin
   CreateBlob:=false;
   i:=FieldDef.FieldNo;
@@ -801,17 +806,26 @@ begin
       desttype:=SQLFLT8;
       destlen:=sizeof(DBFLT8); //double
       end;
+    ftDate, ftTime,
     ftDateTime:
-      begin
-      dest:=@dbdt;
-      desttype:=SQLDATETIME;
-      destlen:=sizeof(dbdt);
-      end;
+      if srctype in [SYBMSDATE, SYBMSTIME, SYBMSDATETIME2, SYBMSDATETIMEOFFSET] then // dbwillconvert(srctype, SYBMSDATETIME2)
+        begin
+        dest:=@dbdta;
+        desttype:=SYBMSDATETIME2;
+        destlen:=sizeof(dbdta);
+        end
+      else
+        begin
+        dest:=@dbdt;
+        desttype:=SQLDATETIME;
+        destlen:=sizeof(dbdt);
+        end;
     ftBCD:
       begin
-      dest:=@f;
+      // FreeTDS 0.91 does not support converting from numeric to money
+      //desttype:=SQLMONEY;
       desttype:=SQLFLT8;
-      destlen:=sizeof(DBFLT8); //double
+      destlen:=sizeof(currency);
       end;
     ftFmtBCD:
       begin
@@ -857,7 +871,10 @@ begin
             (ClientCharset = ccISO88591) {hack: FreeTDS} then
           StrPLCopy(PChar(dest), UTF8Encode(PChar(dest)), destlen);
       end;
-    ftDateTime:
+    ftDate, ftTime, ftDateTime:
+      if desttype = SYBMSDATETIME2 then
+        PDateTime(buffer)^ := dbdatetimeallcrack(@dbdta)
+      else
       begin
         //detect DBDATEREC version by pre-setting dbdr
         dbdr.millisecond := -1;
@@ -874,7 +891,7 @@ begin
         end;
       end;
     ftBCD:
-      PCurrency(buffer)^:=FloatToCurr(f);
+      PCurrency(buffer)^ := FloatToCurr(PDouble(buffer)^); //PCurrency(buffer)^ := dbmoneytocurr(buffer);
     ftFmtBCD:
       PBCD(buffer)^:=StrToBCD(bcdstr, FSQLFormatSettings); //PBCD(buffer)^:=dbnumerictobcd(dbnum);
   end;

+ 29 - 16
packages/fcl-db/src/sqldb/mssql/readme.txt

@@ -1,17 +1,29 @@
 Compiling FreeTDS DB-Lib with MS Visual C++ 2005/2008/2010:
 ===========================================================
 1.   Download sources from www.freetds.org
-2.   Open FreeTDS.dsw from /win32/msvc6 source directory
-2.1  in libTDS / Header Files edit config.h and comment "HAVE_INTTYPES_H":
-     /* #undef HAVE_INTTYPES_H */
-     (http://www.freetds.org/userguide/osissues.htm#WINDOWS)
-2.2  In Build / Configuration Manager select "Release"
-     Right-click on project "dblib_dll" and select "Properties". Note: select Configuration Properties first if in Visual C++ 2010.
-     C/C++ / Preprocesor / Preprocessor Definitions add "MSDBLIB" (optionally default TDS version "TDS71")
-     Linker / Input / Additional Dependencies add ".\tds_Release\libTDS.lib"
-     Linker / General / Output File change from ".\dbdll_Release\dblib_dll.dll" to ".\dbdll_Release\dblib.dll"
-3.   Build "dblib_dll"
-4.   The dblib.dll will appear in the .\dbdll_Release\ subdirectory
+2.1  Using Perl interpreter generate files:
+     perl.exe encodings.pl > encodings.h
+     perl.exe num_limits.pl > num_limits.h
+     perl.exe tds_willconvert.pl > tds_willconvert.h
+     perl.exe types.pl ../../misc/types.csv ../../include/freetds/proto.h > tds_types.h
+2.2  Copy include/tds_sysdep_public.h.in to tds_sysdep_public.h and replace "@dblib_define@" with "#define MSDBLIB"
+     Copy include/freetds/version.h.in to version.h and replace "@..@" variables
+     Copy win32/config.h.in to config.h
+3.   Open FreeTDS.sln from root source directory
+3.1  in TDS / Header Files edit config.h and comment "HAVE_INTTYPES_H":
+       /* #define HAVE_INTTYPES_H 1 */
+       (http://www.freetds.org/userguide/osissues.htm#WINDOWS)
+3.2  In Build / Configuration Manager select "Release"
+     Right-click on project "db-lib" and select "Properties". Note: select Configuration Properties first if in Visual C++ 2010.
+       General / Configuration Type = "Dynamic library (.dll)"
+       C/C++ / Preprocesor / Preprocessor Definitions add "MSDBLIB" (optionally default TDS version "TDS71")
+       Linker / Input / Additional Dependencies add "ws2_32.lib"
+                      / Module Definition File = "..\..\win32\dblib.def"
+       Linker / General / Output File change from "$(OutDir)\$(ProjectName).dll" to "$(OutDir)\dblib.dll"
+     Right-click on project "replacements" and select "Properties".
+       C/C++ / Preprocesor / Preprocessor Definitions add "_WIN32_WINNT=0x0400"
+4.   Build "db-lib"
+5.   The dblib.dll will appear in the Release\ subdirectory
      Note: To avoid dependency on msvc*.dll you can set in C/C++ / Code Generation / Runtime Library : "Multi-threaded (/MT)" in all projects
 
      To build dblib.dll under MS Visual C++ 2010 Express for Win64 you must:
@@ -30,11 +42,12 @@ Compiling FreeTDS with iconv support:
 	Developer files: http://gnuwin32.sourceforge.net/downlinks/libiconv-lib-zip.php (include/iconv.h and lib/libiconv.lib)
 	Binaries: http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php  (bin/libiconv2.dll)
     and extract them to a directory, e.g. the directory iconv below your root FreeTDS folder	
-2.  in libTDS / Header Files edit config.h and uncomment /* #undef HAVE_ICONV */:
-    #define HAVE_ICONV 1
-3.  in Project properties:
-    libTDS: C/C++ / General / Additional Include Directories add path to "include/iconv.h" (e.g. "..\..\iconv\src\libiconv\1.9.2\libiconv-1.9.2\include"
-    dblib_dll: Linker / Input / Additional Dependencies add "lib/libiconv.lib" (e.g. "..\..\iconv\lib\libiconv.lib"
+2.  in TDS / Header Files edit config.h and change /* #undef HAVE_ICONV */ to #define HAVE_ICONV 1
+3.  in TDS Project properties:
+      C/C++ / General / Additional Include Directories add path to "include/iconv.h" (e.g. "$(SolutionDir)..\iconv\include"
+    in db-lib Project properties:
+      C/C++ / General / Additional Include Directories add path to "include/iconv.h" (e.g. "$(SolutionDir)..\iconv\include"
+      Linker / Input / Additional Dependencies add "lib/libiconv.lib" (e.g. "$(SolutionDir)..\iconv\lib\libiconv.lib"
 4.  Follow regular compilation instructions above
 5.  Distribute libiconv2.dll with your dblib.dll