Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MySQL Create Procedure
Message
De
29/04/2009 04:55:43
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01396861
Message ID:
01396873
Vues:
57
>I'm adapting Rick Strahl's wwbusiness class (which is designed for MS SQL) to work with MySQL. It uses a stored procedure that I'm having trouble duplicating in MySQL.
>
>
>lcSQL=[CREATE PROCEDURE sp_ww_NewID ]+;
>			[@cName char(30),]+;
>			[@nRetval int OUTPUT ]+;
>			[AS ]+;
>			[UPDATE mytableids ]+;
>			[SET id = id + 1,]+;
>			[@nRetval = id + 1 ]+;
>			[WHERE TableName = @cName ]
>
>
>which is called via SPT with
>
>PRIVATE pnID
>pnID = 0
>lcSQL="Execute sp_ww_NewId '" + lcTableName + "',?@pnID"
>
>
>So my adaption to MySQL is:
>
>lcSQL=[CREATE PROCEDURE sp_ww_NewID (cName char(30), out nRetval integer) ]+;
>		[UPDATE mytableids SET id = id + 1,]+;
>		[nRetval = id + 1 ]+;
>		[WHERE TableName = cName ]
>
>and then calling it via SPT with:
>
>PRIVATE pnID
>pnID = 0
>lcSQL="call sp_ww_NewId('" + lcTableName + "', @pnID)"
>
>
>But attempting to call the stored procedure gives the error message:
>"Connectivity error: [MySQL][ODBC 5.1 Driver][mysqld-5.1.30]Unknown column 'nRetval' in 'field list' [1526:1054]"
>
>What am I doing wrong?


I don't know mySQL but looking at documentation (almost next to none) sounds like:
text to lcSQL noshow
CREATE PROCEDURE sp_ww_NewID (cName char(30), out nRetval integer)
 begin
  UPDATE mytableids SET id = id + 1  WHERE TableName = cName;
  select id from myTableIds where TableName = cName into nRetval;
end
endtext
PS: Wouldn't the call syntax be better like this:
lcSQL="Execute sp_ww_NewId ?m.lcTableName,?@pnID"
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform