Function prepareFunction

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

Prototype

Prepared prepareFunction(
  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 function.
numArgs The number of arguments the stored procedure takes.

Example

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

	exec(cn, `DROP FUNCTION IF EXISTS hello`);
	exec(cn, `
		CREATE FUNCTION hello (s CHAR(20))
		RETURNS CHAR(50) DETERMINISTIC
		RETURN CONCAT('Hello ',s,'!')
	`);

	auto preparedHello = prepareFunction(cn, "hello", 1);
	preparedHello.setArgs("World");
	ResultSet rs = preparedHello.querySet();
	assert(rs.length == 1);
	assert(rs[0][0] == "Hello World!");
}

Authors

Copyright

License