[Urgent question]: When the MySql stored procedure script contains preprocessing statements, _ MySQL cannot be executed.

Source: Internet
Author: User
[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.