Explorar el Código

Merged revisions 4000,4002,4007-4010 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r4000 | joost | 2006-06-29 22:01:52 +0200 (Thu, 29 Jun 2006) | 1 line

+ Fix for ftLargeInt fields from Jesus Reyes
........
r4002 | peter | 2006-06-29 22:47:04 +0200 (Thu, 29 Jun 2006) | 2 lines

* uncomment timestamp constants

........
r4007 | joost | 2006-06-30 00:18:18 +0200 (Fri, 30 Jun 2006) | 1 line

+ Implemented ComposeDateTime for general use
........
r4008 | joost | 2006-06-30 00:33:14 +0200 (Fri, 30 Jun 2006) | 5 lines

- Defined Oracle date/time types
- Fix for recognition of Float-fields
- Implemented support for ftDateTime
- support for ftBCD fields is implemented in r4000
- a fix for the size of string-fields is implemented in r4000
........
r4009 | joost | 2006-06-30 00:41:05 +0200 (Fri, 30 Jun 2006) | 1 line

+ patch to move SetLargeInt and GetLargeInt from TLargeIntfield to TField from Dean Zobec
........
r4010 | joost | 2006-06-30 02:27:15 +0200 (Fri, 30 Jun 2006) | 1 line

+ Support for the use of hostname
........

git-svn-id: branches/fixes_2_0@4023 -

joost hace 19 años
padre
commit
6af0ccfdbd

+ 1 - 0
fcl/db/bufdataset.inc

@@ -257,6 +257,7 @@ begin
     ftBoolean    : result := sizeof(wordbool);
     ftBCD        : result := sizeof(currency);
     ftFloat      : result := sizeof(double);
+    ftLargeInt   : result := sizeof(largeint);
     ftTime,
       ftDate,
       ftDateTime : result := sizeof(TDateTime)

+ 5 - 3
fcl/db/db.pp

@@ -295,6 +295,7 @@ type
     procedure FreeBuffers; virtual;
     function GetAsBoolean: Boolean; virtual;
     function GetAsCurrency: Currency; virtual;
+    function GetAsLargeInt: LargeInt; virtual;
     function GetAsDateTime: TDateTime; virtual;
     function GetAsFloat: Double; virtual;
     function GetAsLongint: Longint; virtual;
@@ -321,6 +322,7 @@ type
     procedure SetAsFloat(AValue: Double); virtual;
     procedure SetAsLongint(AValue: Longint); virtual;
     procedure SetAsInteger(AValue: Integer); virtual;
+    procedure SetAsLargeint(AValue: Largeint); virtual;
     procedure SetAsVariant(AValue: variant); virtual;
     procedure SetAsString(const AValue: string); virtual;
     procedure SetDataType(AValue: TFieldType);
@@ -350,6 +352,7 @@ type
     property AsDateTime: TDateTime read GetAsDateTime write SetAsDateTime;
     property AsFloat: Double read GetAsFloat write SetAsFloat;
     property AsLongint: Longint read GetAsLongint write SetAsLongint;
+    property AsLargeInt: LargeInt read GetAsLargeInt write SetAsLargeInt;
     property AsInteger: Integer read GetAsInteger write SetAsInteger;
     property AsString: string read GetAsString write SetAsString;
     property AsVariant: variant read GetAsVariant write SetAsVariant;
@@ -494,7 +497,7 @@ type
   protected
     function GetAsFloat: Double; override;
     function GetAsLongint: Longint; override;
-    function GetAsLargeint: Largeint; virtual;
+    function GetAsLargeint: Largeint; override;
     function GetAsString: string; override;
     function GetAsVariant: variant; override;
     function GetDataSize: Word; override;
@@ -502,14 +505,13 @@ type
     function GetValue(var AValue: Largeint): Boolean;
     procedure SetAsFloat(AValue: Double); override;
     procedure SetAsLongint(AValue: Longint); override;
-    procedure SetAsLargeint(AValue: Largeint); virtual;
+    procedure SetAsLargeint(AValue: Largeint); override;
     procedure SetAsString(const AValue: string); override;
     procedure SetVarValue(const AValue: Variant); override;
   public
     constructor Create(AOwner: TComponent); override;
     Function CheckRange(AValue : largeint) : Boolean;
     property Value: Longint read GetAsLongint write SetAsLongint;
-    property AsLargeInt: LargeInt read GetAsLargeint write SetAsLargeint;
   published
     property MaxValue: Largeint read FMaxValue write SetMaxValue default 0;
     property MinValue: Largeint read FMinValue write SetMinValue default 0;

+ 11 - 0
fcl/db/fields.inc

@@ -308,6 +308,7 @@ Const
   SDateTime = 'TDateTime';
   SFloat = 'Float';
   SInteger = 'Integer';
+  SLargeInt = 'LargeInt';
   SVariant = 'Variant';
   SString = 'String';
 
@@ -617,6 +618,11 @@ begin
     Result:=-1;
 end;
 
+function TField.GetAsLargeInt: LargeInt;
+begin
+  AccessError(SLargeInt);
+end;
+
 function TField.GetAsCurrency: Currency;
 begin
   Result := GetAsFloat;
@@ -771,6 +777,11 @@ begin
   SetAsLongint(AValue);
 end;
 
+procedure TField.SetAsLargeint(AValue: Largeint);
+begin
+  AccessError(SLargeInt);
+end;
+
 procedure TField.SetAsString(const AValue: string);
 
 begin

+ 5 - 4
fcl/db/sqldb/examples/database.ini

@@ -9,7 +9,7 @@
 # * odbc
 # * postgresql
 
-type=interbase
+type=oracle
 
 # name
 # gives the name of the database that should be used.
@@ -17,7 +17,7 @@ type=interbase
 # used. More information about how to create a dabatase can be find in the
 # documentation of the database-engine.
 
-name=/opt/firebird/examples/employee.fdb
+name=//192.168.3.1/xe
 
 # user
 # name is the name of a user which must have all rights on the selected
@@ -26,11 +26,12 @@ name=/opt/firebird/examples/employee.fdb
 # How to set up users and their rights can be found in the database-engine
 # documentation.
 
-user=sysdba
+user=system
 
 # password
 # password is the password of the provided user. If the password is incorrect,
 # all or one  of the test could fail.
 
-password=masterkey
+password=rosivrepus
 
+hostname=

+ 56 - 6
fcl/db/sqldb/oracle/oracleconnection.pp

@@ -75,6 +75,8 @@ type
 
 implementation
 
+uses math;
+
 ResourceString
   SErrEnvCreateFailed = 'The creation of an Oracle environment failed.';
   SErrHandleAllocFailed = 'The allocation of the error handle failed.';
@@ -91,6 +93,9 @@ begin
 end;
 
 procedure TOracleConnection.DoInternalConnect;
+
+var ConnectString : string;
+
 begin
 {$IfDef LinkDynamically}
   InitialiseOCI;
@@ -104,7 +109,10 @@ begin
   if OciHandleAlloc(FOciEnvironment,FOciError,OCI_HTYPE_ERROR,0,FUserMem) <> OCI_SUCCESS then
     DatabaseError(SErrHandleAllocFailed,self);
 
-  if OCILogon2(FOciEnvironment,FOciError,FOciSvcCtx,@username[1],length(username),@password[1],length(password),@databasename[1],length(databasename),OCI_DEFAULT) = OCI_ERROR then
+  if hostname='' then connectstring := databasename
+  else connectstring := '//'+hostname+'/'+databasename;
+
+  if OCILogon2(FOciEnvironment,FOciError,FOciSvcCtx,@username[1],length(username),@password[1],length(password),@connectstring[1],length(connectstring),OCI_DEFAULT) = OCI_ERROR then
     HandleError;
 end;
 
@@ -344,17 +352,31 @@ begin
                                   OFieldType := SQLT_INT;
                                   OFieldSize:= sizeof(integer);
                                   end
-                                else if (oscale = -127) and (OPrecision=0) then
+                                else if (oscale = -127) {and (OPrecision=0)} then
                                   begin
                                   FieldType := ftFloat;
                                   OFieldType := SQLT_FLT;
                                   OFieldSize:=sizeof(double);
-                                  end;
+                                  end
+                                else if (oscale <=4) and (OPrecision<=12) then
+                                  begin
+                                  FieldType := ftBCD;
+                                  FieldSize := sizeof(Currency);
+                                  OFieldType := SQLT_VNU;
+                                  OFieldSize:= 22;
+                                  end
+                                else FieldType := ftUnknown;
                                 end;
         OCI_TYPECODE_CHAR,
         OCI_TYPECODE_VARCHAR,
-        OCI_TYPECODE_VARCHAR2 : begin FieldType := ftString; inc(OFieldsize) ;FieldSize := OFieldSize; OFieldType:=SQLT_STR end;
+        OCI_TYPECODE_VARCHAR2 : begin FieldType := ftString; FieldSize := OFieldSize; inc(OFieldsize) ;OFieldType:=SQLT_STR end;
         OCI_TYPECODE_DATE     : FieldType := ftDate;
+        OCI_TYPECODE_TIMESTAMP,
+        OCI_TYPECODE_TIMESTAMP_LTZ,
+        OCI_TYPECODE_TIMESTAMP_TZ  : begin
+                                     FieldType := ftDateTime;
+                                     OFieldType := SQLT_ODT;
+                                     end;
       else
         FieldType := ftUnknown;
       end;
@@ -394,8 +416,12 @@ end;
 
 function TOracleConnection.LoadField(cursor: TSQLCursor; FieldDef: TFieldDef; buffer: pointer): boolean;
 
-var dt  : TDateTime;
-    b   : pbyte;
+var dt        : TDateTime;
+    b         : pbyte;
+    size,i    :  byte;
+    exp       : shortint;
+    cur       : Currency;
+    odt       : POCIdateTime;
 
 begin
   with cursor as TOracleCursor do if fieldbuffers[FieldDef.FieldNo-1].ind = -1 then
@@ -405,6 +431,25 @@ begin
     result := True;
     case FieldDef.DataType of
       ftString          : move(fieldbuffers[FieldDef.FieldNo-1].buffer^,buffer^,FieldDef.Size);
+      ftBCD             :  begin
+                           b := fieldbuffers[FieldDef.FieldNo-1].buffer;
+                           size := b[0];
+                           cur := 0;
+                           if (b[1] and $80)=$80 then // then the number is positive
+                             begin
+                             exp := (b[1] and $7f)-65;
+                             for i := 2 to size do
+                               cur := cur + (b[i]-1) * intpower(100,-(i-2)+exp);
+                             end
+                           else
+                             begin
+                             exp := (not(b[1]) and $7f)-65;
+                             for i := 2 to size-1 do
+                               cur := cur + (101-b[i]) * intpower(100,-(i-2)+exp);
+                             cur := -cur;
+                             end;
+                           move(cur,buffer^,FieldDef.Size);
+                           end;
       ftFloat           : move(fieldbuffers[FieldDef.FieldNo-1].buffer^,buffer^,sizeof(double));
       ftInteger         : move(fieldbuffers[FieldDef.FieldNo-1].buffer^,buffer^,sizeof(integer));
       ftDate  : begin
@@ -412,6 +457,11 @@ begin
                 dt := EncodeDate((b[0]-100)*100+(b[1]-100),b[2],b[3]);
                 move(dt,buffer^,sizeof(dt));
                 end;
+      ftDateTime : begin
+                   odt := fieldbuffers[FieldDef.FieldNo-1].buffer;
+                   dt := ComposeDateTime(EncodeDate(odt^.year,odt^.month,odt^.day), EncodeTime(odt^.hour,odt^.min,odt^.sec,0));
+                   move(dt,buffer^,sizeof(dt));
+                   end;
     else
       Result := False;
 

+ 1 - 1
packages/base/oracle/oci.inc

@@ -2917,7 +2917,7 @@ uses ctypes,
     POCIParam = pointer;          // OCI PARameter descriptor
     POCIComplexObjectComp = pointer; // OCI COR descriptor
     POCIROWID = pointer;          // OCI ROWID descriptor
-    POCIDateTime = pointer;       // OCI DateTime descriptor
+//    POCIDateTime = pointer;       // OCI DateTime descriptor
     POCIInterval = pointer;       // OCI Interval descriptor
     POCIUcb = pointer;            // OCI User Callback descriptor
     POCIServerDNs = pointer;      // OCI server DN descriptor

+ 26 - 0
packages/base/oracle/oratypes.pp

@@ -269,6 +269,32 @@ in define line 272 *)
 //    const
 //       MINSIZE_TMAXVAL:size_t = 4294967295;
 
+type
+    POCITime = ^OCITime;
+    OCITime = packed record
+      OCITimeHH      : ub1;
+      OCITimeMM      : ub1;
+      OCITimeSS      : ub1;
+    end;
+
+    POCIDate = ^OCIDate;
+    OCIDate = packed record
+      OCIDateYYYY    : sb2;
+      OCIDateMM      : ub1;
+      OCIDateDD      : ub1;
+      OCIDateTime    : OCITime;
+    end;
+
+    POCIDateTime = ^TOCIDate;
+    TOCIDate = packed record
+      Year           : sb2;
+      Month          : ub1;
+      Day            : ub1;
+      Hour           : ub1;
+      Min            : ub1;
+      Sec            : ub1;
+    end;
+
 implementation
 
   function UB1MASK : longint;

+ 7 - 7
packages/base/oracle/oro_interface.inc

@@ -738,19 +738,19 @@
 //     OCI_TYPECODE_CFILE = SQLT_CFILE;
   { the following are ANSI datetime datatypes added in 8.1  }
   { SQL/OTS TIME  }
-//     OCI_TYPECODE_TIME = SQLT_TIME;
+     OCI_TYPECODE_TIME = SQLT_TIME;
   { SQL/OTS TIME_TZ  }
-//     OCI_TYPECODE_TIME_TZ = SQLT_TIME_TZ;
+     OCI_TYPECODE_TIME_TZ = SQLT_TIME_TZ;
   { SQL/OTS TIMESTAMP  }
-//     OCI_TYPECODE_TIMESTAMP = SQLT_TIMESTAMP;
+     OCI_TYPECODE_TIMESTAMP = SQLT_TIMESTAMP;
   { SQL/OTS TIMESTAMP_TZ  }
-//     OCI_TYPECODE_TIMESTAMP_TZ = SQLT_TIMESTAMP_TZ;
+     OCI_TYPECODE_TIMESTAMP_TZ = SQLT_TIMESTAMP_TZ;
   { TIMESTAMP_LTZ  }
-//     OCI_TYPECODE_TIMESTAMP_LTZ = SQLT_TIMESTAMP_LTZ;
+     OCI_TYPECODE_TIMESTAMP_LTZ = SQLT_TIMESTAMP_LTZ;
   { SQL/OTS INTRVL YR-MON  }
-//     OCI_TYPECODE_INTERVAL_YM = SQLT_INTERVAL_YM;
+     OCI_TYPECODE_INTERVAL_YM = SQLT_INTERVAL_YM;
   { SQL/OTS INTRVL DAY-SEC  }
-//     OCI_TYPECODE_INTERVAL_DS = SQLT_INTERVAL_DS;
+     OCI_TYPECODE_INTERVAL_DS = SQLT_INTERVAL_DS;
   { Urowid type  }
 //     OCI_TYPECODE_UROWID = SQLT_RDD;
   { first Open Type Manager typecode  }

+ 7 - 6
rtl/objpas/sysutils/dati.inc

@@ -43,17 +43,18 @@ begin
     Result:=0;
 end;
 
+{==============================================================================}
+{   Public functions                                                           }
+{==============================================================================}
+
+{   ComposeDateTime converts a Date and a Time into one TDateTime   }
 function ComposeDateTime(Date,Time : TDateTime) : TDateTime;
 
 begin
-  if Date < 0 then Result := Date - Time
-  else Result := Date + Time;
+  if Date < 0 then Result := trunc(Date) - frac(Time)
+  else Result := trunc(Date) + frac(Time);
 end;
 
-{==============================================================================}
-{   Public functions                                                           }
-{==============================================================================}
-
 {   DateTimeToTimeStamp converts DateTime to a TTimeStamp   }
 
 function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;

+ 1 - 0
rtl/objpas/sysutils/datih.inc

@@ -100,6 +100,7 @@ function TryEncodeDate(Year, Month, Day: Word; var Date: TDateTime): Boolean;
 function TryEncodeTime(Hour, Min, Sec, MSec: Word; var Time: TDateTime): Boolean;
 function EncodeDate(Year, Month, Day :word): TDateTime;
 function EncodeTime(Hour, Minute, Second, MilliSecond:word): TDateTime;
+function ComposeDateTime(Date,Time : TDateTime) : TDateTime;
 procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
 function DecodeDateFully(const DateTime: TDateTime; var Year, Month, Day, DOW: Word): Boolean;
 procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);