SOL9 Sample: DeleteFromTableApplet

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * DeleteFromTableApplet.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// 2009/05/20
// Assumes that environment of SQL Server 2008 and SQLClient1.0 
// Please create a database 'Sample' for this example

// 2012/10/07 Updated
// Please run InsertIntoTableApplet.ext before running this program.
/*
In this sample, we assume the following table exists:

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 {

class DeleteFromTableApplet: public ADOApplet {

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

public:
  ~DeleteFromTableApplet()
  {
  }

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

    //SQL statements
    const wchar_t* sqls[] = {
      L"Delete from SolUser where ID=1",
      L"Delete From SolUser where Name like 'Thomas%'"};
 
    connection.beginTrans();
    printf("2 OK, connection.beginTrans()\n");

    for (int i = 0; i<sizeof(sqls)/sizeof(sqls[0]); i++) {
      ADORecordset recordset;
      try {
        long recordsAffected = connection.execute(_bstr_t(sqls[i]), recordset);
        printf("3 OK, connection.execute(\"%S\")\n",
          sqls[i]);
        printf("4 Really deleted record count(RecordsAffected)=%ld\n", recordsAffected);
  
      } catch (_com_error& e) {
        COMError error(e);
        error.dump();
      } catch (...) {
        printf("Exception:Unknown\n");
      }
    }

    connection.commitTrans();
    printf("5 OK, connection.commitTrans()\n");
  }
};

}


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

    DeleteFromTableApplet deleteFromTableApplet(argc, argv);

    deleteFromTableApplet.start();

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

Last modified: 2 May 2016

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