|
@@ -14,7 +14,8 @@ type
|
|
|
|
|
|
TTestFieldTypes= class(TTestCase)
|
|
TTestFieldTypes= class(TTestCase)
|
|
private
|
|
private
|
|
- procedure TestFldType(ADatatype: TFieldType; ADataSize: integer; ASQLTypeDecl: string; ATestValuesStr: array of string; ATestValues: array of variant);
|
|
|
|
|
|
+ procedure CreateTableWithFieldType(ADatatype : TFieldType; ASQLTypeDecl : string);
|
|
|
|
+ procedure TestFieldDeclaration(ADatatype: TFieldType; ADataSize: integer);
|
|
protected
|
|
protected
|
|
procedure SetUp; override;
|
|
procedure SetUp; override;
|
|
procedure TearDown; override;
|
|
procedure TearDown; override;
|
|
@@ -22,7 +23,9 @@ type
|
|
published
|
|
published
|
|
procedure TestInt;
|
|
procedure TestInt;
|
|
procedure TestString;
|
|
procedure TestString;
|
|
|
|
+ procedure TestUnlVarChar;
|
|
procedure TestDate;
|
|
procedure TestDate;
|
|
|
|
+ procedure TestDateTime; // bug 6925
|
|
end;
|
|
end;
|
|
|
|
|
|
implementation
|
|
implementation
|
|
@@ -33,27 +36,36 @@ procedure TTestFieldTypes.TestInt;
|
|
|
|
|
|
const
|
|
const
|
|
testValuesCount = 17;
|
|
testValuesCount = 17;
|
|
- testValuesInt : Array[0..testValuesCount-1] of integer = (-maxInt,-maxSmallint-1,-maxSmallint,-256,-255,-128,-127,-1,0,1,127,128,255,256,maxSmallint,maxSmallint+1,MaxInt);
|
|
|
|
|
|
+ testValues : Array[0..testValuesCount-1] of integer = (-maxInt,-maxSmallint-1,-maxSmallint,-256,-255,-128,-127,-1,0,1,127,128,255,256,maxSmallint,maxSmallint+1,MaxInt);
|
|
|
|
|
|
var
|
|
var
|
|
- TestValues : array[0..testValuesCount-1] of variant;
|
|
|
|
- TestValuesStr : array[0..testValuesCount-1] of string;
|
|
|
|
- i : byte;
|
|
|
|
|
|
+ i : byte;
|
|
|
|
|
|
begin
|
|
begin
|
|
|
|
+ CreateTableWithFieldType(ftInteger,'INT');
|
|
|
|
+ TestFieldDeclaration(ftInteger,4);
|
|
|
|
+
|
|
for i := 0 to testValuesCount-1 do
|
|
for i := 0 to testValuesCount-1 do
|
|
|
|
+ TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (' + inttostr(testValues[i]) + ')');
|
|
|
|
+
|
|
|
|
+ with TSQLDBConnector(DBConnector).Query do
|
|
begin
|
|
begin
|
|
- TestValues[i] := testValuesInt[i];
|
|
|
|
- TestValuesStr[i] := inttostr(testValuesInt[i]);
|
|
|
|
|
|
+ Open;
|
|
|
|
+ for i := 0 to testValuesCount-1 do
|
|
|
|
+ begin
|
|
|
|
+ AssertEquals(testValues[i],fields[0].AsInteger);
|
|
|
|
+ Next;
|
|
|
|
+ end;
|
|
|
|
+ close;
|
|
end;
|
|
end;
|
|
- TestFldType(ftInteger,4,'INT',TestValuesStr,TestValues);
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TTestFieldTypes.TestString;
|
|
procedure TTestFieldTypes.TestString;
|
|
|
|
|
|
const
|
|
const
|
|
- testValuesCount = 15;
|
|
|
|
- testValuesS : Array[0..testValuesCount-1] of string = (
|
|
|
|
|
|
+ testValuesCount = 19;
|
|
|
|
+ testValues : Array[0..testValuesCount-1] of string = (
|
|
|
|
+ '',
|
|
'a',
|
|
'a',
|
|
'ab',
|
|
'ab',
|
|
'abc',
|
|
'abc',
|
|
@@ -68,72 +80,210 @@ const
|
|
'1234567890',
|
|
'1234567890',
|
|
'_!@#$%^&*(',
|
|
'_!@#$%^&*(',
|
|
')-;:/?.<>',
|
|
')-;:/?.<>',
|
|
- '~`|{}-='
|
|
|
|
|
|
+ '~`|{}- =', // note that there's no \ (backslash) since some db's uses that as escape-character
|
|
|
|
+ ' WRaP ',
|
|
|
|
+ 'wRaP ',
|
|
|
|
+ ' wRAP'
|
|
);
|
|
);
|
|
|
|
|
|
var
|
|
var
|
|
- TestValues : array[0..testValuesCount-1] of variant;
|
|
|
|
- TestValuesStr : array[0..testValuesCount-1] of string;
|
|
|
|
i : byte;
|
|
i : byte;
|
|
|
|
|
|
begin
|
|
begin
|
|
|
|
+ CreateTableWithFieldType(ftString,'VARCHAR(10)');
|
|
|
|
+ TestFieldDeclaration(ftString,11);
|
|
|
|
+
|
|
for i := 0 to testValuesCount-1 do
|
|
for i := 0 to testValuesCount-1 do
|
|
|
|
+ TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + testValues[i] + ''')');
|
|
|
|
+
|
|
|
|
+ with TSQLDBConnector(DBConnector).Query do
|
|
begin
|
|
begin
|
|
- TestValuesStr[i] := '''' + testValuesS[i] + '''';
|
|
|
|
- TestValues[i] := testValuesS[i];
|
|
|
|
|
|
+ Open;
|
|
|
|
+ for i := 0 to testValuesCount-1 do
|
|
|
|
+ begin
|
|
|
|
+ AssertEquals(testValues[i],fields[0].AsString);
|
|
|
|
+ Next;
|
|
|
|
+ end;
|
|
|
|
+ close;
|
|
end;
|
|
end;
|
|
- TestFldType(ftString,11,'VARCHAR(10)',TestValuesStr,TestValues);
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTestFieldTypes.TestUnlVarChar;
|
|
|
|
+
|
|
|
|
+const
|
|
|
|
+ testValuesCount = 21;
|
|
|
|
+ testValues : Array[0..testValuesCount-1] of string = (
|
|
|
|
+ '',
|
|
|
|
+ 'a',
|
|
|
|
+ 'ab',
|
|
|
|
+ 'abc',
|
|
|
|
+ 'abcd',
|
|
|
|
+ 'abcde',
|
|
|
|
+ 'abcdef',
|
|
|
|
+ 'abcdefg',
|
|
|
|
+ 'abcdefgh',
|
|
|
|
+ 'abcdefghi',
|
|
|
|
+ 'abcdefghij',
|
|
|
|
+ 'lMnOpQrStU',
|
|
|
|
+ '1234567890',
|
|
|
|
+ '_!@#$%^&*(',
|
|
|
|
+ ')-;:/?.<>',
|
|
|
|
+ '~`|{}- =',
|
|
|
|
+ ' WRaP ',
|
|
|
|
+ 'wRaP ',
|
|
|
|
+ ' wRAP',
|
|
|
|
+ '0123456789',
|
|
|
|
+ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_+-=][|}{;:,./<>?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_+-=][|}{;:,./<>?' + 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_+-=][|}{;:,./<>?'
|
|
|
|
+ + 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_+-=][|}{;:,./<>?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_+-=][|}{;:,./<>?' + 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_+-=][|}{;:,./<>?'
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+var
|
|
|
|
+ i : byte;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ CreateTableWithFieldType(ftString,'VARCHAR');
|
|
|
|
+ TestFieldDeclaration(ftString,dsMaxStringSize+1);
|
|
|
|
|
|
|
|
+ for i := 0 to testValuesCount-1 do
|
|
|
|
+ TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + testValues[i] + ''')');
|
|
|
|
+
|
|
|
|
+ with TSQLDBConnector(DBConnector).Query do
|
|
|
|
+ begin
|
|
|
|
+ Open;
|
|
|
|
+ for i := 0 to testValuesCount-1 do
|
|
|
|
+ begin
|
|
|
|
+ AssertEquals(testValues[i],fields[0].AsString);
|
|
|
|
+ Next;
|
|
|
|
+ end;
|
|
|
|
+ close;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
|
|
procedure TTestFieldTypes.TestDate;
|
|
procedure TTestFieldTypes.TestDate;
|
|
|
|
|
|
const
|
|
const
|
|
- testValuesCount = 14;
|
|
|
|
|
|
+ testValuesCount = 18;
|
|
|
|
+ testValues : Array[0..testValuesCount-1] of string = (
|
|
|
|
+ '2000-01-01',
|
|
|
|
+ '1999-12-31',
|
|
|
|
+ '2004-02-29',
|
|
|
|
+ '2004-03-01',
|
|
|
|
+ '1991-02-28',
|
|
|
|
+ '1991-03-01',
|
|
|
|
+ '2040-10-16',
|
|
|
|
+ '1977-09-29',
|
|
|
|
+ '1800-03-30',
|
|
|
|
+ '1650-05-10',
|
|
|
|
+ '1754-06-04',
|
|
|
|
+ '0904-04-12',
|
|
|
|
+ '0199-07-09',
|
|
|
|
+ '0001-01-01',
|
|
|
|
+ '1899-12-29',
|
|
|
|
+ '1899-12-30',
|
|
|
|
+ '1899-12-31',
|
|
|
|
+ '1900-01-01'
|
|
|
|
+ );
|
|
|
|
|
|
var
|
|
var
|
|
- TestValues : array[0..testValuesCount-1] of variant;
|
|
|
|
- TestValuesStr : array[0..testValuesCount-1] of string;
|
|
|
|
i : byte;
|
|
i : byte;
|
|
-s : tdatetime;
|
|
|
|
|
|
+
|
|
begin
|
|
begin
|
|
- TestValues[0] := EncodeDate(2000,1,1);
|
|
|
|
- TestValues[1] := EncodeDate(1999,12,31);
|
|
|
|
- TestValues[2] := EncodeDate(2004,2,29);
|
|
|
|
- TestValues[3] := EncodeDate(2004,3,1);
|
|
|
|
- TestValues[4] := EncodeDate(1991,2,28);
|
|
|
|
- TestValues[5] := EncodeDate(1991,3,1);
|
|
|
|
- TestValues[6] := EncodeDate(2040,10,16);
|
|
|
|
- TestValues[7] := EncodeDate(1977,9,29);
|
|
|
|
- TestValues[8] := EncodeDate(1800,3,30);
|
|
|
|
- TestValues[9] := EncodeDate(1650,5,1);
|
|
|
|
- TestValues[10] := EncodeDate(1754,6,4);
|
|
|
|
- TestValues[11] := EncodeDate(904,4,12);
|
|
|
|
- TestValues[12] := EncodeDate(199,7,9);
|
|
|
|
- TestValues[13] := EncodeDate(1,1,1);
|
|
|
|
|
|
+ CreateTableWithFieldType(ftDate,'DATE');
|
|
|
|
+ TestFieldDeclaration(ftDate,8);
|
|
|
|
+
|
|
for i := 0 to testValuesCount-1 do
|
|
for i := 0 to testValuesCount-1 do
|
|
- TestValuesStr[i] := '''' + FormatDateTime('yyyy/mm/dd',testValues[i]) + '''';
|
|
|
|
- TestFldType(ftDate,8,'DATE',TestValuesStr,TestValues);
|
|
|
|
|
|
+ TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + testValues[i] + ''')');
|
|
|
|
+
|
|
|
|
+// TSQLDBConnector(DBConnector).Transaction.CommitRetaining; // For debug-purposes
|
|
|
|
+
|
|
|
|
+ with TSQLDBConnector(DBConnector).Query do
|
|
|
|
+ begin
|
|
|
|
+ Open;
|
|
|
|
+ for i := 0 to testValuesCount-1 do
|
|
|
|
+ begin
|
|
|
|
+ AssertEquals(testValues[i],FormatDateTime('yyyy/mm/dd',fields[0].AsDateTime));
|
|
|
|
+ Next;
|
|
|
|
+ end;
|
|
|
|
+ close;
|
|
|
|
+ end;
|
|
|
|
+
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TTestFieldTypes.TestFldType(ADatatype: TFieldType; ADataSize: integer;
|
|
|
|
- ASQLTypeDecl: string; ATestValuesStr: array of string; ATestValues: array of variant);
|
|
|
|
|
|
+procedure TTestFieldTypes.TestDateTime;
|
|
|
|
|
|
-var
|
|
|
|
- i : byte;
|
|
|
|
- testValuesCount : integer;
|
|
|
|
|
|
+const
|
|
|
|
+ testValuesCount = 31;
|
|
|
|
+ testValues : Array[0..testValuesCount-1] of string = (
|
|
|
|
+ '2000-01-01',
|
|
|
|
+ '1999-12-31',
|
|
|
|
+ '2004-02-29',
|
|
|
|
+ '2004-03-01',
|
|
|
|
+ '1991-02-28',
|
|
|
|
+ '1991-03-01',
|
|
|
|
+ '2040-10-16',
|
|
|
|
+ '1977-09-29',
|
|
|
|
+ '1800-03-30',
|
|
|
|
+ '1650-05-10',
|
|
|
|
+ '1754-06-04',
|
|
|
|
+ '0904-04-12',
|
|
|
|
+ '0199-07-09',
|
|
|
|
+ '0001-01-01',
|
|
|
|
+ '1899-12-29',
|
|
|
|
+ '1899-12-30',
|
|
|
|
+ '1899-12-31',
|
|
|
|
+ '1900-01-01',
|
|
|
|
+ '1899-12-30 18:00:51',
|
|
|
|
+ '1899-12-30 04:00:51',
|
|
|
|
+ '1899-12-29 04:00:51',
|
|
|
|
+ '1899-12-29 18:00:51',
|
|
|
|
+ '2000-01-01 10:00:00',
|
|
|
|
+ '2000-01-01 23:59:59',
|
|
|
|
+ '2100-01-01 01:01:01',
|
|
|
|
+ '1400-02-03 12:21:53',
|
|
|
|
+ '1333-02-03 21:44:21',
|
|
|
|
+ '1994-03-06 11:54:30',
|
|
|
|
+ '1903-04-02 01:04:02',
|
|
|
|
+ '1815-09-24 03:47:22',
|
|
|
|
+ '0354-11-20 21:25:15'
|
|
|
|
+ );
|
|
|
|
|
|
- s : string;
|
|
|
|
|
|
+var
|
|
|
|
+ i : byte;
|
|
|
|
|
|
begin
|
|
begin
|
|
- testValuesCount := length(ATestValues);
|
|
|
|
|
|
+ CreateTableWithFieldType(ftDateTime,'TIMESTAMP');
|
|
|
|
+ TestFieldDeclaration(ftDateTime,8);
|
|
|
|
+
|
|
|
|
+ for i := 0 to testValuesCount-1 do
|
|
|
|
+ TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + testValues[i] + ''')');
|
|
|
|
|
|
|
|
+ with TSQLDBConnector(DBConnector).Query do
|
|
|
|
+ begin
|
|
|
|
+ Open;
|
|
|
|
+ for i := 0 to testValuesCount-1 do
|
|
|
|
+ begin
|
|
|
|
+ if length(testValues[i]) < 12 then
|
|
|
|
+ AssertEquals(testValues[i],FormatDateTime('yyyy/mm/dd',fields[0].AsDateTime))
|
|
|
|
+ else
|
|
|
|
+ AssertEquals(testValues[i],FormatDateTime('yyyy/mm/dd hh:mm:ss',fields[0].AsDateTime));
|
|
|
|
+ Next;
|
|
|
|
+ end;
|
|
|
|
+ close;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TTestFieldTypes.CreateTableWithFieldType(ADatatype: TFieldType;
|
|
|
|
+ ASQLTypeDecl: string);
|
|
|
|
+begin
|
|
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (FT ' +ASQLTypeDecl+ ')');
|
|
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (FT ' +ASQLTypeDecl+ ')');
|
|
|
|
|
|
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
|
|
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
|
|
TSQLDBConnector(DBConnector).Transaction.CommitRetaining;
|
|
TSQLDBConnector(DBConnector).Transaction.CommitRetaining;
|
|
|
|
+end;
|
|
|
|
|
|
|
|
+procedure TTestFieldTypes.TestFieldDeclaration(ADatatype: TFieldType;
|
|
|
|
+ ADataSize: integer);
|
|
|
|
+begin
|
|
with TSQLDBConnector(DBConnector).Query do
|
|
with TSQLDBConnector(DBConnector).Query do
|
|
begin
|
|
begin
|
|
SQL.Clear;
|
|
SQL.Clear;
|
|
@@ -141,23 +291,11 @@ begin
|
|
|
|
|
|
Open;
|
|
Open;
|
|
AssertEquals(1,FieldCount);
|
|
AssertEquals(1,FieldCount);
|
|
- AssertEquals('FT',fields[0].FieldName);
|
|
|
|
|
|
+ AssertTrue(CompareText('FT',fields[0].FieldName)=0);
|
|
AssertEquals(ADataSize,fields[0].DataSize);
|
|
AssertEquals(ADataSize,fields[0].DataSize);
|
|
AssertTrue(ADatatype=fields[0].DataType);
|
|
AssertTrue(ADatatype=fields[0].DataType);
|
|
Close;
|
|
Close;
|
|
-
|
|
|
|
- for i := 0 to testValuesCount-1 do
|
|
|
|
- TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (' + AtestValuesStr[i] + ')');
|
|
|
|
-// TSQLDBConnector(DBConnector).Transaction.CommitRetaining; // For debug-purposes
|
|
|
|
- Open;
|
|
|
|
- for i := 0 to testValuesCount-1 do
|
|
|
|
- begin
|
|
|
|
- AssertEquals(string(AtestValues[i]),fields[0].Value);
|
|
|
|
- Next;
|
|
|
|
- end;
|
|
|
|
- close;
|
|
|
|
end;
|
|
end;
|
|
- TSQLDBConnector(DBConnector).Transaction.Rollback;
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TTestFieldTypes.SetUp;
|
|
procedure TTestFieldTypes.SetUp;
|
|
@@ -167,17 +305,19 @@ end;
|
|
|
|
|
|
procedure TTestFieldTypes.TearDown;
|
|
procedure TTestFieldTypes.TearDown;
|
|
begin
|
|
begin
|
|
|
|
+ if assigned(DBConnector) then
|
|
|
|
+ TSQLDBConnector(DBConnector).Transaction.Rollback;
|
|
FreeAndNil(DBConnector);
|
|
FreeAndNil(DBConnector);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TTestFieldTypes.RunTest;
|
|
procedure TTestFieldTypes.RunTest;
|
|
begin
|
|
begin
|
|
- if dbtype = 'interbase' then
|
|
|
|
|
|
+ if (dbtype = 'interbase') or
|
|
|
|
+ (dbtype = 'postgresql') then
|
|
inherited RunTest;
|
|
inherited RunTest;
|
|
end;
|
|
end;
|
|
|
|
|
|
initialization
|
|
initialization
|
|
-
|
|
|
|
- RegisterTest(TTestFieldTypes);
|
|
|
|
|
|
+ RegisterTest(TTestFieldTypes);
|
|
end.
|
|
end.
|
|
|
|
|