浏览代码

fcl-db:
- for MSSQL map TINYINT to ftWord
- for SQLite map TINYINT to ftSmallint
- TestTinyint

git-svn-id: trunk@25036 -

lacak 12 年之前
父节点
当前提交
7c110e9b42

+ 3 - 2
packages/fcl-db/src/sqldb/mssql/mssqlconn.pp

@@ -644,7 +644,8 @@ begin
   case SQLDataType of
   case SQLDataType of
     SQLCHAR:             Result:=ftFixedChar;
     SQLCHAR:             Result:=ftFixedChar;
     SQLVARCHAR:          Result:=ftString;
     SQLVARCHAR:          Result:=ftString;
-    SQLINT1, SQLINT2:    Result:=ftSmallInt;
+    SQLINT1:             Result:=ftWord;
+    SQLINT2:             Result:=ftSmallInt;
     SQLINT4, SQLINTN:    Result:=ftInteger;
     SQLINT4, SQLINTN:    Result:=ftInteger;
     SYBINT8:             Result:=ftLargeInt;
     SYBINT8:             Result:=ftLargeInt;
     SQLFLT4, SQLFLT8,
     SQLFLT4, SQLFLT8,
@@ -761,7 +762,7 @@ begin
       inc(dest, sizeof(Word));
       inc(dest, sizeof(Word));
       desttype:=SQLBINARY;
       desttype:=SQLBINARY;
       end;
       end;
-    ftSmallInt:
+    ftSmallInt, ftWord:
       begin
       begin
       desttype:=SQLINT2;
       desttype:=SQLINT2;
       destlen:=sizeof(DBSMALLINT); //smallint
       destlen:=sizeof(DBSMALLINT); //smallint

+ 7 - 6
packages/fcl-db/src/sqldb/sqlite/sqlite3conn.pp

@@ -374,13 +374,14 @@ Type
   end;
   end;
   
   
 Const
 Const
-  FieldMapCount = 27;
+  FieldMapCount = 28;
   FieldMap : Array [1..FieldMapCount] of TFieldMap = (
   FieldMap : Array [1..FieldMapCount] of TFieldMap = (
    (n:'INT'; t: ftInteger),
    (n:'INT'; t: ftInteger),
-   (n:'LARGEINT'; t:ftlargeInt),
-   (n:'BIGINT'; t:ftlargeInt),
-   (n:'WORD'; t: ftWord),
+   (n:'LARGEINT'; t:ftLargeInt),
+   (n:'BIGINT'; t:ftLargeInt),
    (n:'SMALLINT'; t: ftSmallint),
    (n:'SMALLINT'; t: ftSmallint),
+   (n:'TINYINT'; t: ftSmallint),
+   (n:'WORD'; t: ftWord),
    (n:'BOOLEAN'; t: ftBoolean),
    (n:'BOOLEAN'; t: ftBoolean),
    (n:'REAL'; t: ftFloat),
    (n:'REAL'; t: ftFloat),
    (n:'FLOAT'; t: ftFloat),
    (n:'FLOAT'; t: ftFloat),
@@ -395,8 +396,8 @@ Const
    (n:'CHAR'; t: ftFixedChar),
    (n:'CHAR'; t: ftFixedChar),
    (n:'NUMERIC'; t: ftBCD),
    (n:'NUMERIC'; t: ftBCD),
    (n:'DECIMAL'; t: ftBCD),
    (n:'DECIMAL'; t: ftBCD),
-   (n:'TEXT'; t: ftmemo),
-   (n:'CLOB'; t: ftmemo),
+   (n:'TEXT'; t: ftMemo),
+   (n:'CLOB'; t: ftMemo),
    (n:'BLOB'; t: ftBlob),
    (n:'BLOB'; t: ftBlob),
    (n:'NCHAR'; t: ftFixedWideChar),
    (n:'NCHAR'; t: ftFixedWideChar),
    (n:'NVARCHAR'; t: ftWideString),
    (n:'NVARCHAR'; t: ftWideString),

+ 53 - 2
packages/fcl-db/tests/testfieldtypes.pas

@@ -6,7 +6,7 @@ unit TestFieldTypes;
 interface
 interface
 
 
 uses
 uses
-  Classes, SysUtils, fpcunit, testutils, testregistry,
+  Classes, SysUtils, fpcunit, testregistry,
   db;
   db;
 
 
 type
 type
@@ -24,7 +24,7 @@ type
     procedure TestSQLFieldType(ADatatype: TFieldType; ASQLTypeDecl: string;
     procedure TestSQLFieldType(ADatatype: TFieldType; ASQLTypeDecl: string;
       ADataSize: integer; AGetSQLTextProc: TGetSQLTextProc;
       ADataSize: integer; AGetSQLTextProc: TGetSQLTextProc;
       ACheckFieldValueProc: TCheckFieldValueProc);
       ACheckFieldValueProc: TCheckFieldValueProc);
-    procedure TestXXParamQuery(ADatatype : TFieldType; ASQLTypeDecl : string; testValuescount : integer; Cross : boolean = false);
+    procedure TestXXParamQuery(ADatatype : TFieldType; ASQLTypeDecl : string; testValuesCount : integer; Cross : boolean = false);
     procedure TestSetBlobAsParam(asWhat : integer);
     procedure TestSetBlobAsParam(asWhat : integer);
   protected
   protected
     procedure SetUp; override;
     procedure SetUp; override;
@@ -76,6 +76,7 @@ type
 
 
     procedure TestLargeRecordSize;
     procedure TestLargeRecordSize;
     procedure TestInt;
     procedure TestInt;
+    procedure TestTinyint;
     procedure TestNumeric;
     procedure TestNumeric;
     procedure TestFloat;
     procedure TestFloat;
     procedure TestDate;
     procedure TestDate;
@@ -304,6 +305,56 @@ begin
     end;
     end;
 end;
 end;
 
 
+procedure TTestFieldTypes.TestTinyint;
+const
+  testValuesCount = 5;
+  testValues : Array[0..testValuesCount-1] of byte = (0,1,127,128,255);
+var
+  datatype: string;
+  fieldtype: TFieldType;
+  i: integer;
+begin
+  case SQLServerType of
+    ssMSSQL:
+      begin
+      datatype  := 'TINYINT';
+      fieldtype := ftWord;
+      end;
+    ssMySQL:
+      begin
+      datatype  := 'TINYINT UNSIGNED';
+      fieldtype := ftWord;
+      end;
+    ssSQLite:
+      begin
+      datatype  := 'TINYINT';
+      fieldtype := ftSmallint;
+      end;
+    else
+      begin
+      fieldtype := ftSmallint;
+      datatype  := FieldtypeDefinitions[fieldtype];
+      end;
+  end;
+
+  CreateTableWithFieldType(fieldtype, datatype);
+  TestFieldDeclaration(fieldtype, sizeof(Smallint));
+
+  with TSQLDBConnector(DBConnector) do
+  begin
+    for i := 0 to testValuesCount-1 do
+      ExecuteDirect('insert into FPDEV2 (FT) values (' + inttostr(testValues[i]) + ')');
+
+    Query.Open;
+    for i := 0 to testValuesCount-1 do
+    begin
+      AssertEquals(testValues[i], Query.Fields[0].AsInteger);
+      Query.Next;
+    end;
+    Query.Close;
+  end;
+end;
+
 procedure TTestFieldTypes.TestNumeric;
 procedure TTestFieldTypes.TestNumeric;
 
 
 const
 const