Friday, May 29, 2009

SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]The FOR XML clause is not allowed in a CURSOR statement

If your sql query is something like
$sqlQuery = “select * from test for xml raw('MyItem'), elements, root('MyRoot')”;

As a work around you can wrap it inside another select statement.
$sqlQuery = "select (" . $sqlQuery . ")";

This query will return the record set containing only one row and one column and which will be your xml. You can get the xml by using odbc_result($queryResult,1);

If the xml is too big you may need to configure max_execution_time, memory_limit and odbc.defaultlrl in the php.ini file according to your requirement.

Tuesday, May 19, 2009

How to print out a variable’s value/message from a MySQL stored procedure?

You can use a simple select inside the stored procedure.

Example:

DELIMITER //

DROP PROCEDURE IF EXISTS printTest//

CREATE PROCEDURE printTest(myVar int)

BEGIN

IF myVar <> 0 THEN
SELECT myVar;
ELSE
SELECT 'Got 0';
END IF;

END//


DELIMITER ;

Monday, May 11, 2009

MySQL – Create Table – Difference between TYPE and ENGINE

The syntax 'TYPE' is deprecated and will be removed in MySQL 5.2. Please use 'ENGINE' instead.

Eg:
CREATE TABLE my_table
(
my_key INTEGER NOT NULL,
my_data VARCHAR(20) NOT NULL
PRIMARY KEY (my_key)
) ENGINE = INNODB;

How to get MySQL warnings?

Use ‘SHOW WARNINGS’ command.