mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 07:19:27 +02:00
fcl-db:
- for MSSQL map TINYINT to ftWord - for SQLite map TINYINT to ftSmallint - TestTinyint git-svn-id: trunk@25036 -
This commit is contained in:
parent
206e5eb475
commit
7c110e9b42
@ -644,7 +644,8 @@ begin
|
||||
case SQLDataType of
|
||||
SQLCHAR: Result:=ftFixedChar;
|
||||
SQLVARCHAR: Result:=ftString;
|
||||
SQLINT1, SQLINT2: Result:=ftSmallInt;
|
||||
SQLINT1: Result:=ftWord;
|
||||
SQLINT2: Result:=ftSmallInt;
|
||||
SQLINT4, SQLINTN: Result:=ftInteger;
|
||||
SYBINT8: Result:=ftLargeInt;
|
||||
SQLFLT4, SQLFLT8,
|
||||
@ -761,7 +762,7 @@ begin
|
||||
inc(dest, sizeof(Word));
|
||||
desttype:=SQLBINARY;
|
||||
end;
|
||||
ftSmallInt:
|
||||
ftSmallInt, ftWord:
|
||||
begin
|
||||
desttype:=SQLINT2;
|
||||
destlen:=sizeof(DBSMALLINT); //smallint
|
||||
|
@ -374,13 +374,14 @@ Type
|
||||
end;
|
||||
|
||||
Const
|
||||
FieldMapCount = 27;
|
||||
FieldMapCount = 28;
|
||||
FieldMap : Array [1..FieldMapCount] of TFieldMap = (
|
||||
(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:'TINYINT'; t: ftSmallint),
|
||||
(n:'WORD'; t: ftWord),
|
||||
(n:'BOOLEAN'; t: ftBoolean),
|
||||
(n:'REAL'; t: ftFloat),
|
||||
(n:'FLOAT'; t: ftFloat),
|
||||
@ -395,8 +396,8 @@ Const
|
||||
(n:'CHAR'; t: ftFixedChar),
|
||||
(n:'NUMERIC'; 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:'NCHAR'; t: ftFixedWideChar),
|
||||
(n:'NVARCHAR'; t: ftWideString),
|
||||
|
@ -6,7 +6,7 @@ unit TestFieldTypes;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, fpcunit, testutils, testregistry,
|
||||
Classes, SysUtils, fpcunit, testregistry,
|
||||
db;
|
||||
|
||||
type
|
||||
@ -24,7 +24,7 @@ type
|
||||
procedure TestSQLFieldType(ADatatype: TFieldType; ASQLTypeDecl: string;
|
||||
ADataSize: integer; AGetSQLTextProc: TGetSQLTextProc;
|
||||
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);
|
||||
protected
|
||||
procedure SetUp; override;
|
||||
@ -76,6 +76,7 @@ type
|
||||
|
||||
procedure TestLargeRecordSize;
|
||||
procedure TestInt;
|
||||
procedure TestTinyint;
|
||||
procedure TestNumeric;
|
||||
procedure TestFloat;
|
||||
procedure TestDate;
|
||||
@ -304,6 +305,56 @@ begin
|
||||
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;
|
||||
|
||||
const
|
||||
|
Loading…
Reference in New Issue
Block a user