aboutsummaryrefslogtreecommitdiff
path: root/mssql/stored-proc/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-11-19 13:54:39 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-11-19 13:54:39 +0200
commit0aa976237df26be9415c5aac335ab43e026db077 (patch)
tree31287238d51a0eb5e056fb8b26ca9cbbc646dca2 /mssql/stored-proc/driver.cxx
parent092cb7d916b8ebc83cacab849010acd04f56d38d (diff)
Allow empty runtime and execute views
Use them to handle INSERT/UPDATE SQL Server stored procedures.
Diffstat (limited to 'mssql/stored-proc/driver.cxx')
-rw-r--r--mssql/stored-proc/driver.cxx116
1 files changed, 84 insertions, 32 deletions
diff --git a/mssql/stored-proc/driver.cxx b/mssql/stored-proc/driver.cxx
index 60c4d27..2878486 100644
--- a/mssql/stored-proc/driver.cxx
+++ b/mssql/stored-proc/driver.cxx
@@ -126,7 +126,46 @@ main (int argc, char* argv[])
{
create_procedure (
- *db, "insert_object",
+ *db, "insert_object_id",
+ "(@n INT, @s VARCHAR(512))"
+ "AS"
+ " INSERT INTO mssql_stored_proc_object([num], [str])"
+ " VALUES(@n, @s);");
+
+ {
+ typedef mssql::query<insert_object> query;
+
+ transaction t (db->begin ());
+
+ db->query_one<insert_object> (
+ query::_val (4) + "," + query::_val ("d"));
+
+ auto_ptr<object> o (db->load<object> (4));
+ cout << o->num << " " << o->str << endl
+ << endl;
+
+ t.commit ();
+ }
+
+ {
+ typedef mssql::query<no_result> query;
+
+ transaction t (db->begin ());
+
+ db->query_one<no_result> (
+ "EXEC insert_object_id" + query::_val (5) + "," + query::_val ("e"));
+
+ auto_ptr<object> o (db->load<object> (5));
+ cout << o->num << " " << o->str << endl
+ << endl;
+
+ t.commit ();
+ }
+ }
+
+ {
+ create_procedure (
+ *db, "insert_object_id",
"(@n INT, @s VARCHAR(512), @id INT = NULL OUTPUT)"
"AS"
" INSERT INTO mssql_stored_proc_object([num], [str])"
@@ -134,43 +173,56 @@ main (int argc, char* argv[])
" SET @id = SCOPE_IDENTITY();"
" RETURN 123;");
- create_procedure (
- *db, "insert_object_odb",
- "(@n INT, @s VARCHAR(512))"
- "AS"
- " DECLARE @id INT;"
- " DECLARE @ret INT;"
- " DECLARE @tbl TABLE(dummy INT);"
- " EXEC @ret = insert_object @n, @s, @id OUTPUT;"
- " SELECT @ret, @id;");
+ typedef mssql::query<insert_object_id> query;
- // An alternative implementation that produces a different
- // result set configuration at the ODBC level.
- //
- /*
- create_procedure (
- *db, "insert_object_odb",
- "(@n INT, @s VARCHAR(512))"
- "AS"
- " DECLARE @id INT;"
- " DECLARE @ret INT;"
- " DECLARE @tbl TABLE(dummy INT);"
- " INSERT INTO @tbl EXEC @ret = insert_object @n, @s, @id OUTPUT;"
- " SELECT @ret, @id;");
- */
+ {
+ create_procedure (
+ *db, "insert_object_id_odb",
+ "(@n INT, @s VARCHAR(512))"
+ "AS"
+ " DECLARE @id INT;"
+ " DECLARE @ret INT;"
+ " DECLARE @tbl TABLE(dummy INT);"
+ " EXEC @ret = insert_object_id @n, @s, @id OUTPUT;"
+ " SELECT @ret, @id;");
- typedef mssql::query<select_objects> query;
+ transaction t (db->begin ());
- transaction t (db->begin ());
+ insert_object_id io (
+ db->query_value<insert_object_id> (
+ query::_val (6) + "," + query::_val ("f")));
- insert_object io (
- db->query_value<insert_object> (
- query::_val (4) + "," + query::_val ("d")));
+ cout << io.ret << " " << io.id << endl
+ << endl;
- cout << io.ret << " " << io.id << endl
- << endl;
+ t.commit ();
+ }
- t.commit ();
+ // An alternative implementation that produces a different
+ // result set configuration at the ODBC level.
+ //
+ {
+ create_procedure (
+ *db, "insert_object_id_odb",
+ "(@n INT, @s VARCHAR(512))"
+ "AS"
+ " DECLARE @id INT;"
+ " DECLARE @ret INT;"
+ " DECLARE @tbl TABLE(dummy INT);"
+ " INSERT INTO @tbl EXEC @ret = insert_object_id @n, @s, @id OUTPUT;"
+ " SELECT @ret, @id;");
+
+ transaction t (db->begin ());
+
+ insert_object_id io (
+ db->query_value<insert_object_id> (
+ query::_val (7) + "," + query::_val ("g")));
+
+ cout << io.ret << " " << io.id << endl
+ << endl;
+
+ t.commit ();
+ }
}
}
catch (const odb::exception& e)