Subject RE: [firebird-support] Problem with Execute statement
Author Paul Mercea
Thanks Helen an Adam for your response.

SYS_LOCATION table have this definition:
CREATE TABLE SYS_LOCATION (
LOC_ID SHORTID NOT NULL /* SHORTID = INTEGER */,
LOC_NAME NAME /* NAME = VARCHAR(30) */
);
Inserts:
INSERT INTO SYS_LOCATION (LOC_ID, LOC_NAME) VALUES (1, 'Head Office');

INSERT INTO SYS_LOCATION (LOC_ID, LOC_NAME) VALUES (2, 'Sale Point 1');
INSERT INTO SYS_LOCATION (LOC_ID, LOC_NAME) VALUES (3, 'Sale Point 2');
INSERT INTO SYS_LOCATION (LOC_ID, LOC_NAME) VALUES (4, 'WareHouse');

I made this changes in proecdure:
CREATE PROCEDURE T2 (
T VARCHAR(50))
RETURNS (
IDN VARCHAR(50),
IDL INTEGER)
AS
DECLARE VARIABLE STRSQL VARCHAR(200);
begin
strsql='select loc_id , loc_name from '||T;
for execute statement strsql into :idl, :idn do
begin
suspend;
end

end^

It's not working, but...If I chage strsql like Adam said:
strsql='select loc_id , cast(loc_name as varchar(50)) from '||T;

IT"S WORKING...
Little strange, no???

-----Original Message-----
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of Helen Borrie
Sent: Sunday, April 09, 2006 4:16 AM
To: firebird-support@yahoogroups.com
Subject: RE: [firebird-support] Problem with Execute statement

At 03:11 AM 9/04/2006, you wrote:

>-----Original Message-----
>
>I want to create generic procedure to execute sql statements passed as
>variable.
>I have made this test procedure to verify if is working:
>
>CREATE PROCEDURE T2 (
> T VARCHAR(20))
>RETURNS (
> IDN VARCHAR(30),
> IDL INTEGER)
>AS
>DECLARE VARIABLE STRSQL VARCHAR(50);
>begin
> strsql='select loc_id, loc_name from '||T;
> for execute statement :strsql into :idl, :idn do
> begin
> suspend;
> end
>
>end
>
>I pass table name (SYS_LOCATION) and I get this error message:
>"Variable type (position 0) in EXECUTE STATEMENT 'select loc_id, loc_name
>from SY' INTO does not match returned column type.
>Password required"
>If I change strsql='select loc_id, loc_name from '||T||' '; I get message:
>"Variable type (position 1) in EXECUTE ......"
>Same message if I modify like this:
>strsql='select loc_id, loc_name from ';
>for execute statement :strsql ||T into :idl, :idn do
>
>Error message:
>ISC ERROR CODE:335544829
>
>ISC ERROR MESSAGE:
>Variable type (position 1) in EXECUTE STATEMENT 'select loc_id, loc_name
>from SY' INTO does not match returned column type
>password required

1. Ignore the procedure debugger, it's only as good as its local
parser can make it and that, in turn, is only as good as what the
parser author designed.

2. You have at least three errors here.

a) misdeclaration of the input variable for the table
identifier. Identifiers are char(31). Varchar(31) would be
OK; varchar(20) is not, so this is the cause of the type mismatch.

b) the variable for the input string is probably too short. You
don't have to be mean with this - make it at least as long as the
static byte count + 32.

c) considering that you have mismatched lengths in both of those
areas, review the definitions of your output variables, e.g. if the
data for loc_id is BigInt, there will be an overflow in idl, and if
the defined length of loc_name is longer than 30, you will get an
overflow there.

./hb



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Visit http://firebird.sourceforge.net and click the Resources item
on the main (top) menu. Try Knowledgebase and FAQ links !

Also search the knowledgebases at http://www.ibphoenix.com

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Yahoo! Groups Links