SOL9 Sample: ADOErrorsApplet

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * ADOErrorsApplet.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 table 'Person'
// 

#include <sol/sql/ADOApplet.h>
#include <sol/sql/ADOErrors.h>
#include <sol/String.h>
#include <sol/Locale.h>

namespace SOL {

class ADOErrorsApplet: public ADOApplet {

public:
  /**
   * Constructor
   */
  ADOErrorsApplet()
    :ADOApplet()
  {
  }

public:
  ~ADOErrorsApplet()
  {
  }

public:
  /**
   * ADOErrorsApplet main procedure
   */
  virtual void run()
  {
    printf("1 Start\n");
    ADOConnection connection = getConnection();
    
    //SQL statement
    _bstr_t query("SELECT * FROM Person");

    printf("2 Try to connection.execute(\"%s\")\n", (const char*)query);
    
    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() ){
      const char* names[] = {"UserID", "Telephone", "Email"};
      for (int i=0; i< sizeof(names)/sizeof(names[0]); i++) {
        _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, TCHAR** argv)
{
  Locale locale;

  ADOErrorsApplet errorsApplet;

  try {
  
    //If openConnection fails, it throws an IException  
    errorsApplet.openConnection();
  
    errorsApplet.start();

  } catch (_com_error& e) {
    printf("\nCaught an IException thrown from an operation.\n"
      "Probably it's caused applet.openConnection.\n");
    ADOErrors errors;
    if(errorsApplet.getErrors(errors)) {
      errors.dump();
    }
  }
}


Last modified: 2 May 2016

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