SOL9 Sample: CreateTableApplet
|
1 Screenshot
2 Source code
/*
* CreateTableApplet.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2009/05/20
// Assumes that environment of SQL Server 2008 and SQLClient1.0
// Please create a database 'Sample' for this example
// 2012/10/07 Updated
// 1 Create database 'Sample'
// 2 Create table 'SolUser' on the database 'Sample'.
/*
Create Table SolUser(ID int not NULL primary key,
Name varchar(255) not NULL,
Sex varchar(10),
Age int,
Birthday Date,
Nationality varchar(255),
Email varchar(255),
Telephone varchar(128),
Address varchar(255),
Company varchar(255))
*/
#include <sol/sql/ADOApplet.h>
#include <sol/Locale.h>
namespace SOL {
class CreateTableApplet: public ADOApplet {
public:
/**
* Constructor
*/
CreateTableApplet(int argc, const TCHAR** argv)
:ADOApplet(argc, argv)
{
}
public:
~CreateTableApplet()
{
}
public:
/**
* CreateTableApplet main procedure
*/
virtual void run()
{
printf("1 Start\n");
ADOConnection connection = getConnection();
_bstr_t database = "Sample";
try {
_bstr_t createDatabase = "Create Database " + database;
ADORecordset recordset;
connection.execute(createDatabase, recordset);
printf("2 OK, connection.execute(\"%S\")\n",
(const wchar_t*)createDatabase);
} catch (_com_error& e) {
COMError error(e);
error.dump();
} catch (...) {
printf("Exception: Create database\n");
}
try {
_bstr_t useDatabase = "Use " + database;
ADORecordset recordset;
long recordsAffected = connection.execute(useDatabase, recordset);
printf("3 OK, connection.execute(\"%S\") recordsAffected(%ld)\n",
(const wchar_t*)useDatabase, recordsAffected);
} catch (_com_error& e) {
COMError error(e);
error.dump();
} catch (...) {
printf("Exception: Use database\n");
}
try {
//SQL statement
_bstr_t dropTable = "Drop Table SolUser";
ADORecordset recordset;
long recordsAffected = connection.execute(dropTable, recordset);
printf("4 OK, connection.execute(\"%S\") recordsAffected(%ld)\n",
(const wchar_t*)dropTable, recordsAffected);
} catch (_com_error& e) {
COMError error(e);
error.dump();
} catch (...) {
printf("Exception: Drop table\n");
}
//SQL statement
_bstr_t createTable = "Create Table SolUser(ID int not NULL primary key,\n"
"Name varchar(255) not NULL,\n"
"Sex varchar(10),\n"
"Age int,\n"
"Birthday Date,\n"
"Nationality varchar(255),\n"
"Email varchar(255),\n"
"Telephone varchar(128),\n"
"Address varchar(255),\n"
"Company varchar(255))";
try {
ADORecordset recordset;
long recordsAffected = connection.execute(createTable, recordset);
printf("5 OK, connection.execute(\"%S\") recordsAffected(%ld)\n",
(const wchar_t*)createTable, recordsAffected);
} catch (_com_error& e) {
COMError error(e);
error.dump();
} catch (...) {
printf("Exception: Creat table\n");
}
}
};
}
// Console application starts here.
void _tmain(int argc, const TCHAR** argv)
{
Locale locale;
try {
CreateTableApplet createTableApplet(argc, argv);
createTableApplet.start();
} catch(Exception& ex){
ex.dump();
} catch(...){
printf("Exception:Unknown\n");
}
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.