SOL9 Sample: ADOStreamApplet

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * ADOStreamApplet.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

// Assume there exists a file "person.xml" in this current folder.
// It will be used to Stream::loadFileFile method.

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

namespace SOL {

class ADOStreamApplet: public ADOApplet {

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

public:
  ~ADOStreamApplet()
  {
  }

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

    ADORecordset recordset;
    recordset.createInstance();

    _bstr_t query("SELECT * FROM Person");    
    _tprintf(_T("2 Try to open a recordset for source = \"%s\"\n"), (const TCHAR*)query);
    recordset.open(
      query,
      connection.getConnectionPtr(),
      ADODB::adOpenStatic,    //This is for Recordset::find method.
      ADODB::adLockReadOnly);
    printf("3 OK, opened a recordset\n");
    
    _bstr_t criteria = "Email LIKE 'foo@%'";
    printf("4 Try to call recordset.find() method with a criteria \"%s\"\n", 
        (const TCHAR*)criteria);
    recordset.find(criteria, 0, ADODB::adSearchForward);
    printf("5 OK. found a record for a criteria = \"%s\"\n",
           (const TCHAR*)criteria);
  
    // Persist the recordset to an xml file by calling save with a file name
    // and ADODB::adPersistXML
  
    //Create an instance of ADOStream.
    ADOStream stream;
    stream.createInstance();
    printf("6 OK, created an instance of ADOStream\n");

    stream.putType(ADODB::adTypeText);

    printf("7 Try to open the stream without parameters.\n");
    stream.open();
    printf("8 OK, stream.open()\n");
      
    stream.putPosition(0L);

    const TCHAR* xmlFileName = _T("person.xml");
    _tprintf(_T("9 Try to call stream.loadFromFile(\"\")\n"), xmlFileName);
    stream.loadFromFile(xmlFileName);      
    _tprintf(_T("10 OK, stream.loadFromFile(\"%s\") \n"), xmlFileName);
      
    _variant_t destination((IDispatch*)stream.getStreamPtr());

    printf("11 Try to save a recordset to a stream in adPersistXmL\n");
    recordset.save(destination, ADODB::adPersistXML);
    printf("12 OK, saved the recordset to a stream\n");

    recordset.close();

    const TCHAR* fileName = _T("personstream.xml");
    _tprintf(_T("13 Try to stream.saveToFile(\"%s\")\n"), fileName);
    stream.saveToFile(fileName, ADODB::adSaveCreateOverWrite);
    _tprintf(_T("14 OK, saved a stream to the fileName:%s\n"), (const TCHAR*)fileName);

    stream.close();
  }
};

}


// Console application starts here.
void _tmain(int argc, const TCHAR** argv)
{
  Locale locale;
  try {

    ADOStreamApplet streamApplet(argc, argv);

    streamApplet.start();

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



Last modified: 2 May 2016

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