SOL9 Sample: CreateDatabaseApplet
|
1 Screenshot
2 Source code
/*
* CreateDatabaseApplet.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2009/06/01
// Assumes that environment of SQL Server 2008 and SQLClient1.0
// 2012/10/07 Updated
// 1 Create Database "Solarsystem"
// 2 Create Table "XUser"
// Create Table XUser (
// ID int not NULL primary key,
// Name varchar(255) not NULL,
// Email varchar(255),
// MobilePhone varchar(128),
// Age int,
// Birthday Date,
// Salary smallmoney,
// Updated DateTime)
#include <sol/sql/ADOApplet.h>
#include <sol/Locale.h>
namespace SOL {
/**
* ADO applet subclass derived from SOL::ADOApplet class.
*/
class CreateDatabaseApplet: public ADOApplet {
public:
/**
* Constructor
*/
CreateDatabaseApplet(int argc, const TCHAR** argv)
:ADOApplet(argc, argv)
{
}
public:
~CreateDatabaseApplet()
{
}
private:
void executeSql(__in ADOConnection& connection, __in _bstr_t& sql)
{
try {
ADORecordset recordset;
connection.execute(sql, recordset);
printf("OK, executeSql: connection.execute(\"%S\")\n", (const wchar_t*)sql);
} catch (_com_error& e) {
COMError error(e);
error.dump();
}
}
private:
void executeSql(__in ADOConnection& connection, __in _bstr_t& sql, __out ADORecordset& recordset)
{
try {
connection.execute(sql, recordset);
printf("OK, executeSql: connection.execute(\"%S\")\n", (const wchar_t*)sql);
} catch (_com_error& e) {
COMError error(e);
error.dump();
}
}
public:
/**
* CreateDatabaseApplet main procedure
*/
virtual void run()
{
printf("1 Start\n");
ADOConnection connection = getConnection();
_bstr_t database = "Solarsystem";
_bstr_t dropDatabase = "Drop Database " + database ;
_bstr_t createDatabase = "Create Database " + database;
_bstr_t useDatabase = "Use " + database;
_bstr_t createTable = "Create Table XUser (\n"
" ID int not NULL primary key,\n"
" Name varchar(255) not NULL,\n"
" Email varchar(255),\n"
" MobilePhone varchar(128),\n"
" Age int,\n"
" Birthday Date,\n"
" Salary smallmoney, \n"
" Updated DateTime)\n";
_bstr_t insertSql = "Insert into XUser(ID, Name, Email, Updated)\n"
" Values(100, 'someone', 'someone@solarsystemlaboratory.com@earth.sol', GETDATE())";
_bstr_t selectSql = "Select * from XUser";
executeSql(connection, dropDatabase);
executeSql(connection, createDatabase);
executeSql(connection, useDatabase);
executeSql(connection, createTable);
executeSql(connection, insertSql);
ADORecordset recordset;
executeSql(connection, selectSql, recordset);
recordset.dump();
printf("2 End\n");
}
};
}
// Console application starts here.
void _tmain(int argc, const TCHAR** argv)
{
Locale locale;
try {
CreateDatabaseApplet applet(argc, argv);
applet.start();
} catch (Exception& ex){
ex.dump();
} catch (...) {
printf("Exception:Unknown\n");
}
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.