SOL9 Sample: ADOConnectionApplet

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * ADOConnectionApplet.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 {

class ADOConnectionApplet: public ADOApplet {

public:
  /**
   * Constructor
   */
  ADOConnectionApplet(int argc, const TCHAR** argv)
    :ADOApplet(argc, argv)
  {
  }

public:
  ~ADOConnectionApplet()
  {
  }

public:
  /**
   * ADOConnectionApplet main procedure
   */
  virtual void run()
  {
    printf("1 Start\n");
    ADOConnection connection = getConnection();

    ADOCommand command;
    command.createInstance();

    ADOFields colFields;
    command.getFields(_bstr_t("Person"), 
        connection.getConnectionPtr(), colFields); 
    long count = colFields.getCount();
    printf("2 OK, colFields.getCount(): %d\n", count);

    //SQL statement: select 
    _bstr_t query("SELECT * FROM Person");

    ADORecordset recordset;
    long recordsAffected = connection.execute(query, recordset);
    printf("3 OK, connection.execute(\"%S\")\n", (const wchar_t*)query);
    printf("4 RecordsAffected=%ld\n", recordsAffected);
    
    while(!recordset.getadoEOF()){
      printf("\n5 Matched record:\n");
      for (long i = 0L; i<count; i++) {
        ADOField field;
        if (colFields.getItem(i, field)) {
          _bstr_t name = field.getName();

          //Call recordset.getCollect(name);
          _variant_t variant = recordset.getCollect(name);
          _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 {

    ADOConnectionApplet connectionApplet(argc, argv);

    connectionApplet.start();

  } catch(Exception& ex){
    ex.dump();
  } catch(...){
    printf("Exception:Unknown\n");
  }
}


Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.