SOL9 Sample: BookmarksApplet
|
1 Screenshot
2 Source code
/*
* BookmarksApplet.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
// 2012/10/07
// 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));
*/
// 2012/10/07 Updated
// Please run InsertIntoTableApplet.exe before running this program.
#include <sol/sql/ADOApplet.h>
#include <sol/Locale.h>
namespace SOL {
class BookmarksApplet: public ADOApplet {
public:
/**
* Constructor
*/
BookmarksApplet(int argc, const TCHAR** argv)
:ADOApplet(argc, argv)
{
}
public:
~BookmarksApplet()
{
}
public:
/**
* BookmarksApplet main procedure
*/
virtual void run()
{
printf("1 Start\n");
ADOConnection connection = getConnection();
_bstr_t database = "Sample";
try {
_bstr_t useDatabase = "Use " + database;
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();
}
//SQL statement: select
_bstr_t query("SELECT * FROM SolUser");
ADORecordset recordset;
recordset.createInstance();
printf("2 Try to recordset.open()\n");
recordset.open(query, connection.getConnectionPtr(),
ADODB::adOpenStatic, ADODB::adLockReadOnly, ADODB::adCmdText);
printf("3 OK, recordset.open(\"%S\")\n", (const wchar_t*)query);
long count = recordset.getRecordCount();
printf("4 RecordCount=%ld\n", count);
//2012/10/07
if (count > 0) {
srand((unsigned)time(NULL));
long position = rand() % count;
//Move to a some position
recordset.move(position, _variant_t((short)ADODB::adBookmarkFirst) );
printf("5 OK, recordset.move(%ld)\n", position);
_variant_t bookmark1 = recordset.getBookmark();
printf("6 OK, recordset.getBookmark()\n");
recordset.moveFirst();
long i = 0L;
while(!recordset.getadoEOF()){
try {
_variant_t bookmark2 = recordset.getBookmark();
ADODB::CompareEnum result = recordset.compareBookmarks(
bookmark1, bookmark2);
if (result == ADODB::adCompareEqual) {
ADOEnumNames names;
const char* compared = names.getName(result);
printf("7 Comapred Bookmarks matched %ld %ld = %s\n", i, position, compared);
}
} catch (...) {
printf("Exception: Simply ignore it here\n");
}
i++;
recordset.moveNext();
}
}
}
};
}
// Console application starts here.
void _tmain(int argc, const TCHAR** argv)
{
Locale locale;
try {
BookmarksApplet bookmarksApplet(argc, argv);
bookmarksApplet.start();
} catch(Exception& ex){
ex.dump();
} catch(...){
printf("Exception:Unknown\n");
}
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.