Stored Procedure
This will connect to the default server instance and create the example database and table, if necessary. Then it will create or recreate a procedure to insert three rows.
This needs to be linked against scdriver.lib and run with scdriver.dll available.
// used by Microsoft Visual Studio Projects
#include "stdafx.h"
#include "scdriver.h"
#include <iostream>
int main(int argc, char** argv)
{
CConnection conn;
try
{
// Connect to the local machine on the default port
conn.Connect("localhost",999);
// Set up example database and create table and procedure
conn.Execute("CREATE DATABASE IF NOT EXISTS scdriver_example");
conn.GetCompletionStatus();
conn.Execute("USE scdriver_example");
conn.GetCompletionStatus();
conn.Execute("CREATE TABLE IF NOT EXISTS example_run ("
"id UNIQUEIDENTIFIER NOT NULL PRIMARY KEY, "
"added DATETIME NOT NULL PARTITION, "
"description VARCHAR(255))");
conn.GetCompletionStatus();
conn.Execute("DROP PROCEDURE IF EXISTS example_inserter");
conn.GetCompletionStatus();
conn.Execute("CREATE PROCEDURE example_inserter ("
"INSERT INTO example_run VALUES (0,getdate(),?message) "
"INSERT INTO example_run VALUES (0,getdate(),?message) "
"INSERT INTO example_run VALUES (0,getdate(),?message)"
")");
conn.GetCompletionStatus();
// The command object for the call
CCommand procedure_call;
// Set up the command object to run the procedure named
procedure_call.PrepareProcedure(&conn,"example_inserter");
// Put in the parameter value, run the procedure and wait for it to finish
procedure_call.AddParameter("message",DB_VARCHAR,"One message");
procedure_call.Execute();
conn.GetCompletionStatus();
// Put in a different parameter value and repeat
procedure_call.AddParameter("message",DB_VARCHAR,"Another message");
procedure_call.Execute();
conn.GetCompletionStatus();
procedure_call.AddParameter("message",DB_VARCHAR,"Yet another message");
procedure_call.Execute();
conn.GetCompletionStatus();
}
catch (node_exception& e)
{
std::cerr << "Error: " << e.msg << std::endl;
return 1;
}
return 0;
}
Related