SOL9 Sample: ADOCommandApplet
|
1 Screenshot
2 Source code
/*
* ADOCommandApplet.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
// and following table 'Person'
/*
CREATE TABLE Person
(
UserId int,
Telephone varchar(128),
Email varchar(255),
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255));
*/
#include <sol/sql/ADOApplet.h>
#include <sol/Locale.h>
namespace SOL {
/**
* ADO applet subclass derived from SOL::ADOApplet class.
*/
class ADOCommandApplet: public ADOApplet {
public:
/**
* Constructor
*/
ADOCommandApplet(int argc, const TCHAR** argv)
:ADOApplet(argc, argv)
{
}
public:
~ADOCommandApplet()
{
}
public:
/**
* ADOCommandApplet main procedure
*/
virtual void run()
{
printf("1 Start\n");
ADOConnection connection = getConnection();
ADOCommand command;
command.createInstance();
command.putActiveConnection(connection.getConnectionPtr());
command.putCommandText(_bstr_t("SELECT * FROM Person;"));
command.putCommandType(ADODB::adCmdText);
command.putCommandTimeout(20);
ADORecordset recordset;
long recordsAffected = command.execute(recordset, NULL, ADODB::adCmdText);
printf("2 OK, command.execute(\"%S\")\n",
(const wchar_t*)command.getCommandText());
printf("3 RecordsAffected=%ld\n", recordsAffected);
while(!recordset.getadoEOF() ){
printf("\n4 Matched record:\n");
const char* names[] = {"UserID", "Telephone", "Email",
"LastName", "FirstName"};
for (int i=0; i< sizeof(names)/sizeof(names[0]); i++) {
//Call Recordset::getCollect() method.
_variant_t variant = recordset.getCollect(names[i]);
_bstr_t value = "";
COMTypeConverter converter;
converter.toString(variant, value, _bstr_t("(null)"));
printf("5 %s=%S\n", names[i], (const wchar_t*)value);
}
recordset.moveNext();
}
}
};
}
// Console application starts here.
void _tmain(int argc, const TCHAR** argv)
{
Locale locale;
try {
ADOCommandApplet commandApplet(argc, argv);
commandApplet.start();
} catch (Exception& ex){
ex.dump();
} catch (...) {
printf("Exception:Unknown\n");
}
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.