SOL9 Sample: ADOXCreateTableApplet
|
1 Screenshot
2 Source code
/*
* ADOXCreateTableApplet.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2009/06/03
// Assumes that environment of SQL Server 2008 and SQLClient1.0 or Access2007
#include <sol/sql/ADOXApplet.h>
#include <sol/Locale.h>
namespace SOL {
class ADOXCreateTableApplet: public ADOXApplet {
public:
/**
* Constructor
*/
ADOXCreateTableApplet(int argc, const TCHAR** argv)
:ADOXApplet(argc, argv)
{
}
public:
~ADOXCreateTableApplet()
{
}
public:
/**
* ADOXCreateTableApplet main procedure
*/
virtual void run()
{
String encoding = "";
getXMLEncoding(encoding);
printf("<?xml version=\"1.0\" encoding=\"%s\" ?>\n", (const TCHAR*)encoding);
printf("<!-- \n");
printf("1 Start\n");
try {
ADOXCatalog& catalog = getCatalog();
printf("2 OK, getCatalog()\n");
//dumpTables(catalog);
ADOXTables beforeTables;
catalog.getTables(beforeTables);
_bstr_t tablename = "SolSoftware";
long beforeCount = beforeTables.getCount();
printf("3 OK, Before tables count = %ld\n", beforeCount);
ADOXTables tables;
catalog.getTables(tables);
printf("4 OK, catalog.getTables()\n");
ADOXTable table;
table.createInstance();
table.putName(tablename);
table.appendColumn("ID", ADOX::adInteger, 0);
table.appendColumn("Name", ADOX::adVarChar, 255);
table.appendColumn("Version", ADOX::adVarChar, 255);
table.appendColumn("Company", ADOX::adVarChar, 255);
table.appendColumn("Price", ADOX::adInteger, 0);
table.appendColumn("ReleasedDate", ADOX::adDBTimeStamp, 0); //SQL datetime
printf("5 OK, created a table: \"%s\"\n", (const char*)tablename);
try {
printf("6 Tryt to remove the new table from tables provided it already exists\n");
beforeTables.remove(tablename);
beforeTables.refresh();
long afterRemovedCount = beforeTables.getCount();
printf("7 OK, After removed tables count = %ld\n", afterRemovedCount);
} catch (...) {
; //Ignore
}
tables.append(table);
printf("8 OK, appended a table \"%s\" tp tables\n", (const char*)tablename);
ADOXTables afterTables;
catalog.getTables(afterTables);
long afterCount = afterTables.getCount();
printf("9 OK After tables count = %ld\n", afterCount);
ADOXTable foundTable;
afterTables.find("SOLsoftWare", foundTable);
printf("10 OK, afterTabels.find(\"%s\")\n", (const char*)tablename);
printf("-->\n");
foundTable.dump();
printf("<!-- 11 Dumped foundTable=\"%s\" -->\n", (const char*)tablename);
} catch (Exception& ex) {
ex.dump();
} catch (_com_error& ex) {
COMError error(ex);
error.dump();
} catch (...) {
printf("Exception: Unknown\n");
}
}
};
}
// Console application starts here.
void _tmain(int argc, const TCHAR** argv)
{
Locale locale;
try {
ADOXCreateTableApplet 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.