I have an INSERT
with one VARCHAR
parameter.
SQL looks like this:
INSERT INTO FLAGS (TIME_STAMP, FLAG)
SELECT SUBSTRING(@s1 FROM 1 FOR 23), SUBSTRING(@s1 FROM 24 FOR 2)
FROM RDB$DATABASE;
And sending method like this:
using (FbConnection connection = new FbConnection(ConnectionString))
{
try
{
connection.Open();
var transaction = connection.BeginTransaction();
var command = new FbCommand(sqlCommand, connection, transaction);
command.Parameters.Add("@s1", "2018-09-12 08:37:51.00083");
command.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
Column TIME_STAMP
is TIMESTAMP
and column FLAG
is INTEGER
. In the real application there will be several rows in the INSERT, not just one. There will be also more columns so I would like to keep number of parameters for one row as low as possible.
If I run this code, it gives me:
Exception thrown: 'System.FormatException' in FirebirdSql.Data.FirebirdClient.dll
If I change the command like this:
INSERT INTO FLAGS (TIME_STAMP, FLAG)
SELECT SUBSTRING(@s1 FROM 1 FOR 23), CAST(SUBSTRING(@s1 FROM 24 FOR 2) AS INTEGER)
FROM RDB$DATABASE;
It gives me this error:
Exception thrown: 'FirebirdSql.Data.FirebirdClient.FbException' in
FirebirdSql.Data.FirebirdClient.dll
Dynamic SQL Error
SQL error code = -804
Data type unknown
FWIR this should be possible. At least this works in FlameRobin (version with CAST
also works):
SET TERM ^ ;
EXECUTE BLOCK AS
DECLARE s1 VARCHAR(25) = '2018-09-12 08:37:51.00083';
BEGIN
INSERT INTO FLAGS (TIME_STAMP, FLAG)
SELECT SUBSTRING(:s1 FROM 1 FOR 23), SUBSTRING(:s1 FROM 24 FOR 2)
FROM RDB$DATABASE;
END^
SET TERM ; ^
Can someone point me in the right direction?
EDIT
Result should be:
TIME_STAMP | FLAG
------------------------+-----
2018-09-12 08:37:51.000 | 83