Subject | Re: [firebird-support] Windows DateTime into Firebird Database |
---|---|
Author | Helen Borrie |
Post date | 2006-03-10T04:17:35Z |
At 12:48 PM 10/03/2006, you wrote:
time string you are reading from Windows into a datetime literal that
Firebird recognises.
There are several, but the easiest are:
'CCYYMMDD hh:nn:ss.tttt'
'CCYY-MM-DD hh:nn:ss.tttt'
'DD.MM.CCYY hh:nn:ss.tttt'
'MM/DD/CCYY hh:nn:ss.tttt'
Notes that DD/MM/CCYY will NOT work; the format of the time part uses
the 24-hour clock and is not variable; and there is one and only one
space character between the date part and the time part.
./heLen
>I'm having problems getting Windows DateTime into my Firebird DB. IYou will need some function that will convert the format of the date
>defined the table as:
>
>/* Table: PODCASTS, Owner: SYSDBA */
>
>CREATE TABLE "PODCASTS"
>(
> "ID" INTEGER NOT NULL,
> "FILENAME" VARCHAR(255) NOT NULL,
> "DIRECTORY" INTEGER NOT NULL,
> "USEMEDIA" CHAR(1) NOT NULL,
> "FILETYPE" CHAR(5) NOT NULL,
> "CREATIONDATE" TIMESTAMP NOT NULL,
> "USED" CHAR(1) NOT NULL,
> "FILESIZE" INTEGER NOT NULL,
> PRIMARY KEY ("ID")
>);
>
>and a stored procedure to write a record as:
>
>COMMIT WORK;
>SET AUTODDL OFF;
>SET TERM ^ ;
>
>/* Stored procedures */
>
>CREATE PROCEDURE "ADDPODCAST"
>(
> "ID" INTEGER,
> "FILENAME" VARCHAR(255),
> "DIRECTORY" INTEGER,
> "FILESIZE" INTEGER,
> "FILETYPE" CHAR(5),
> "CREATIONDATE" TIMESTAMP,
> "USEMEDIA" CHAR(1),
> "USED" CHAR(1)
>)
>AS
>BEGIN EXIT; END ^
>
>
>ALTER PROCEDURE "ADDPODCAST"
>(
> "ID" INTEGER,
> "FILENAME" VARCHAR(255),
> "DIRECTORY" INTEGER,
> "FILESIZE" INTEGER,
> "FILETYPE" CHAR(5),
> "CREATIONDATE" TIMESTAMP,
> "USEMEDIA" CHAR(1),
> "USED" CHAR(1)
>)
>AS
> BEGIN
> INSERT INTO podcasts (
> id,filename,directory,filesize,filetype,creationdate,usemedia,used
> ) VALUES (
>
>:id,:filename,:directory,:filesize,:filetype,:creationdate,:usemedia,:used
> );
> SUSPEND;
>
> /* Notify listeners of insert */
> POST_EVENT 'insert_sptable1_ins';
>END
> ^
>
>SET TERM ; ^
>COMMIT WORK;
>SET AUTODDL ON;
>
>then in my C# program I do:
>//
>// path is the full path to the file
>
>FileInfo fi = new FileInfo(path);
>
>cmd.CommandType = CommandType.StoredProcedure;
>
>cmd.Parameters.Clear();
>
>cmd.CommandText = "ADDPODCAST";
>
>cmd.Parameters.Add("@ID", ids[(int)FileTypes.Podcasts]++); // integer
>
>cmd.Parameters.Add("@FILENAME", System.IO.Path.GetFileName(path).ToLower());
>
>cmd.Parameters.Add("@DIRECTORY", dirID);
>
>cmd.Parameters.Add("@FILESIZE", fi.Length);
>
>cmd.Parameters.Add("@USEMEDIA", '0');
>
>cmd.Parameters.Add("@USED", '0');
>
>cmd.Parameters.Add("@FILETYPE",fileType);
>
>cmd.Parameters.Add("@CREATIONDATE",fi.CreationTime.Date.ToFileTime());
>// should be the file creation datetime
>
>
>try
>
>{
>
>cmd.ExecuteNonQuery();
>
>}
>
>catch (Exception ex)
>
>{
>
>Trace.WriteLine("Error writing record in AddPodcast " + ex.Message +
>" " + ex.InnerException);
>
>}
>
>Where there is a valid and open connection associted with the
>command. When I try and execute the procedure I get an exception that states:
>
>[System.InvalidCastException] = {"Invalid cast from 'Char' to 'DateTime'."}.
>
>
>
>Any help would be greatly appreciated. All I need to do is write
>the datatime that the file was created and then read. Seemss easy :-)
time string you are reading from Windows into a datetime literal that
Firebird recognises.
There are several, but the easiest are:
'CCYYMMDD hh:nn:ss.tttt'
'CCYY-MM-DD hh:nn:ss.tttt'
'DD.MM.CCYY hh:nn:ss.tttt'
'MM/DD/CCYY hh:nn:ss.tttt'
Notes that DD/MM/CCYY will NOT work; the format of the time part uses
the 24-hour clock and is not variable; and there is one and only one
space character between the date part and the time part.
./heLen