SOL9 Sample: RecordsetFilterApplet
|
1 Screenshot
2 Source code
/*
* RecordsetFilterApplet.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2009/05/28
// Assumes that environment of SQL Server 2008 and SQLClient1.0
// Please create a database 'Sample' for this example
// and following table 'SolUser'
/*
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 {
/**
* ADO applet subclass derived from SOL::ADOApplet class.
*/
class RecordsetFilterApplet: public ADOApplet {
public:
/**
* Constructor
*/
RecordsetFilterApplet(int argc, const TCHAR** argv)
:ADOApplet(argc, argv)
{
}
public:
~RecordsetFilterApplet()
{
}
public:
/**
* RecordsetFilterApplet main procedure
*/
virtual void run()
{
printf("1 Start\n");
ADOConnection connection = getConnection();
try {
_bstr_t useDatabase = "Use Sample";
ADORecordset recordset;
long recordsAffected = connection.execute(useDatabase, recordset);
printf("OK, connection.execute(\"%S\") recordsAffected(%ld)\n",
(const wchar_t*)useDatabase, recordsAffected);
} catch (_com_error& e) {
COMError error(e);
error.dump();
}
ADOCommand command;
command.createInstance();
command.putActiveConnection(connection.getConnectionPtr());
command.putCommandText(_bstr_t("SELECT * FROM SolUser;"));
command.putCommandType(ADODB::adCmdText);
command.putCommandTimeout(20);
ADORecordset recordset;
long recordsAffected = command.execute(recordset, NULL, ADODB::adCmdText);
printf("2 OK, command.execute(\"%S\") recordsAffected(%ld)\n",
(const wchar_t*)command.getCommandText(), recordsAffected);
_bstr_t filter("ID=3000 OR ID=3001");
recordset.putFilter(filter);
printf("3 OK, recordset.putFiler(\"%S\")\n", (const wchar_t*)filter);
_bstr_t gotFilter = (_bstr_t)recordset.getFilter();
printf("4 OK, recordset.getFiler(): \"%S\"\n", (const wchar_t*)gotFilter);
while(!recordset.getadoEOF()){
printf("\n5 Matched record:\n");
ADOFields colFields;
recordset.getFields(colFields);
long count = colFields.getCount();
for (long i = 0; i<count; i++) {
ADOField field;
if (colFields.getItem(i, field)) {
_bstr_t name = field.getName();
//_variant_t variant = recordset.getCollect(name);
_variant_t variant = field.getValue();
_bstr_t value = "";
COMTypeConverter converter;
converter.toString(variant, value);
printf("6 %S=%S\n", (const wchar_t*)name, (const wchar_t*)value);
}
}
recordset.moveNext();
}
}
};
}
// Console application starts here.
void _tmain(int argc, const TCHAR** argv)
{
Locale locale;
try {
RecordsetFilterApplet filterApplet(argc, argv);
filterApplet.start();
} catch (Exception& ex){
ex.dump();
} catch (...) {
printf("Exception:Unknown\n");
}
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.