Function prepareProcedure

Convenience function to create a prepared statement which calls a stored procedure.

OUT parameters are not currently supported. It should generally be possible with MySQL to present them as a result set.

Prototype

Prepared prepareProcedure(
  Connection conn,
  string name,
  int numArgs
);

Throws

MySQLException if there are pending result set items, or if the server has a problem.

Parameters

NameDescription
name The name of the stored procedure.
numArgs The number of arguments the stored procedure takes.

Example

debug(MYSQL_INTEGRATION_TESTS)
{
	import mysql.test.common;
	import mysql.test.integration;
	mixin(scopedCn);
	initBaseTestTables(cn);

	exec(cn, `DROP PROCEDURE IF EXISTS insert2`);
	exec(cn, `
		CREATE PROCEDURE insert2 (IN p1 INT, IN p2 CHAR(50))
		BEGIN
			INSERT INTO basetest (intcol, stringcol) VALUES(p1, p2);
		END
	`);

	auto preparedInsert2 = prepareProcedure(cn, "insert2", 2);
	preparedInsert2.setArgs(2001, "inserted string 1");
	preparedInsert2.exec();

	ResultSet rs = querySet(cn, "SELECT stringcol FROM basetest WHERE intcol=2001");
	assert(rs.length == 1);
	assert(rs[0][0] == "inserted string 1");
}

Authors

Copyright

License