I have defined a MySQL database with a table that includes a field of type varchar(128), I call it fieldinquestion. I use a query to access this field, which usually works nicely. However, when I assign a string to the field, I get an error that I don't understand.
try
Self.FDQuery1.FieldByName('fieldinquestion').AsString:='Hello There'; //or something similar.
except
---> error: 'Could not convert variant of type (String) into type (Double)'
aDataType:=Self.FDQuery1.FieldByName(GCssValidationDisplay).DataType; --datatype is ftString
end;
In the try..except clause, this causes an error, but a verification for the datatype shows it is a string!
Any ideas?
Related
I am trying to execute a stored procedure in using MULE 4.
It expects two inputs, one is a table value parameter and another is an integer.
For the table value parameter, i am using SQLServerDataTable and specifying the tvpName using the public method setTvpName. After that I add the column metadata and add rows with the provided Arraylist of values.
In the DB:Stored Procedure component I use the syntax
CALL [database_name].[stored_procedure_name(:argument1,:argument 2)]
where argument 1 is the TVP and argument 2 is the integer.
But I get the error :
Message : The index 1 is out of range.
Error type : DB:QUERY_EXECUTION
Any ideas on how to better debug the issue or solve it is appreciated.
i have a stored procedure in Sybase ASE with date params in it, so when i created a OLE DB Connection and passing the date parameters to the OLE DB Command,And we are mapping to the parameter with OLEDBType.DBTimeStamp type, datetime param type in stored procedure is smalldatetime.
Here is the sample code.
OLEDBConnection con = new OLEDBConnection(connectionstring);
con.open;
OLEDBCommand cmd = new OLEDBCommand(con);
cmd.QueryString = "dbo.job_xb_new"
cmd.QueryType = "Stored Procedure";
cmd.Parameters.Add("#signoff",OLEType.DBTimeStamp);
cmd.Parameters("#signoff").Value = Datetime.now;
cmd.executeNonQuery(); -----------> ERROR HERE
while executing the store-procedure i am receiving the error.
"Conversion failed because the DateTime data value overflowed the type specified for the DateTime value part in the consumer's buffer" ?
Please help!!!
With the only information given there may be a solution to try.
Change the datatype of your input value to the stored proc to a char/varchar
create procedure dbo.myProc
#inDate varchar(20)
AS
BEGIN
..
END
Perform internal conversion from that with CONVERT before passing to your query.
SET #inDate = CONVERT(datetime,#inDate,[style parameter number])
For troubleshooting, just comment out everything in the procedure and SELECT #inDate first to determine what the data coming in from the OLE DB app looks like. You may be in for a surprise there...
Let's imagine that I have created the stored procedure in SAP HANA database and would like to have optional out parameter with text type, like error details. As I have read to achieve this I should use some default value thus I have done like this:
PROCEDURE "myProcedure"
(
IN inSomeParameter BIGINT,
OUT outResult INTEGER, -- output, result of the operation
OUT outErrorDetail NVARCHAR(32) default ''
)
Unfortunately build failed with the following error:
OUT and IN OUT parameters may not have default expressions
So, I decided to try with null, but it failed the same way. Later I changed the type to integer just to try and it failed exactly same way again.
In the same time this works:
PROCEDURE "myProcedure"
(
IN inSomeParameter BIGINT,
OUT outResult INTEGER, -- output, result of the operation
OUT outErrorDetail TABLE(errorDetails NVARCHAR(32)) default empty
)
but it feels like a huge overkill - to make a table to return only one text value.
Do you have any suggestion how to add optional output parameter?
SQL Script in its current state doesn’t allow for optional OUT parameters.
Why don’t you just set the OUT parameter default value in the procedure body right before the code?
This adds boilerplate code, but you could also use it to convey explicit success messages.
Im want to use a temporary table with dynamic sql but i have an error saying that the column Column, parameter, or variable #3: Cannot find data type MyTable. Must declare the table variable "#CountriesFound".
Here's my code
ALTER PROCEDURE sqlDynamic #countryId int
AS
CREATE TYPE MyTable AS TABLE ([countries] varchar(50));
DECLARE #statement NVARCHAR(MAX)
DECLARE #CountriesFound AS MyTable
INSERT INTO #CountriesFound(countries)
select Name
FROM CountriesFound
SET #statement =
'SELECT name, CASE WHEN (c.name IN (SELECT countries FROM #CountriesFound)) THEN 1
ELSE 0
END as countryFound FROM Country c WHERE c.countryId = #countryId'
EXECUTE sp_executesql #statement,
N'#countryId int, #CountriesFound MyTable READONLY',
#countryId = #countryId,
#CountriesFound=#CountriesFound;
Any idea how to fix it ?
The error you are getting has nothing to do with dynamic sql. You cannot create a stored procedure that uses a User-Defined DataType (MyTable in your example) in the same procedure that is going to create the TYPE. The TYPE has to already be created before the procedure will even let the code compile.
Consider this simplified code:
CREATE PROCEDURE TypeTest
AS
CREATE TYPE MyTable AS TABLE ([Id] int);
DECLARE #mt AS MyTable;
Just executing this will give the error:
Msg 2715, Level 16, State 3, Procedure TypeTest, Line 1 Column,
parameter, or variable #1: Cannot find data type MyTable. Parameter or
variable '#mt' has an invalid data type.
You need to CREATE the TYPE outside of the procedure code before you try to create the procedure. It doesn't make sense to CREATE a TYPE inside a procedure code, since TYPE objects are permanent on the server until they are dropped anyway, and procedures are usually created to be run multiple times.
It would be nice if the SQL Server gave an error message more to this effect, but SQL Server isn't famous for having the most helpful error messages.
My configuration:
Delphi XE
Firebird 2.1
IBObjects 4.9.12
Windows 7 64bits
I get an exception when I try to set a value to a IBOQuery parameter ("Could not convert variant of type (UnicodeString) into type (Double)").
The exception is raised from TIB_Column.SetAsVariant procedure in IB_Components.pas (line 42795). To create this situation, just try to pass a string to a date parameter:
myQuery.paramByName('mydate').AsString := DateToStr(IncDay(Now,5));
During last 25 days I'm trying to solve this situation, but in IBO support list I've got no answers.
Someone have an idea?
IBObjects's architecture is converting(at a moment of execution) all parameters, fields, etc to String or Variants. If your 'mydate' parameter is 'DateTime'(numeric) type then you must fill it up with a corespondent type value. Is not logic to fill an 'numeric' type parameter with a string...
try this
myQuery.paramByName('mydate').AsDateTime:= Now+5; //is the same as David's answer.
or
myQuery.paramByName('mydate').AsFloat:=Now+5; //or IncDay(Now,5)
Best regards,
Radu