[Urgent question]: When the MySql stored procedure script contains preprocessing statements, the script bitsCN.com cannot be executed.
# Stored procedures without preprocessing
# Stored procedure CustomCount. SQL: number of records in each table
Drop Procedure If Exists CustomCount;
Create Procedure CustomCount
(
Out RowNum bigint
)
Not Deterministic
SQL Security Definer
Comment''
Begin
Select Count (*) Into RowNum From uc_members;
End;
------------------------------------------------------------------------
# Stored procedures with preprocessing
# Stored Procedure GetCount. SQL: input the table name and take the number of records of a table Drop Procedure If Exists GetCount;
Create Procedure GetCount
(
TableName varchar (100)
, Out RowNum bigint
)
Not Deterministic
SQL Security Definer
Comment''
Begin
Declare SQLStr varchar (2000) default '';
Set SQLStr = Concat ('SELECT Count (*) Into @ MyNum from', TableName );
Set @ ResultSQL = SQLStr;
Prepare preSQL From @ ResultSQL;
Execute PreSQL;
Deallocate Prepare preSQL;
Set RowNum = @ MyNum;
End;
-------------------------------------------------------------------------
The above two stored procedure scripts run after reading the file content in C #, and the execution of the stored procedure containing preprocessing fails. Why ??
The attachment is the source code example of the. NET Framework 4.0 WinForm running script, including the two stored procedures.
Modify the MySql connection string.
The uc_members table name in CustomCount. SQL can be changed to your table name.
Click here to download
Note:
1. when creating a Web installation package, you need to run the MySql script, which often contains preprocessing scripts.
2. this preprocessing script is mainly used to obtain the output parameter value (similar to the value in GetCount. SQL) during dynamic SQL execution ).
3. you can run the mysql.exe command one by one, or call other mysql's .dllor .exe, because you often do not have the permission to execute local files during Web installation.
4. Web installation is mainly required under the virtual host.
Thank you.
BitsCN.com