Wide Studio Object Reference

| Wide Studio Object Reference |
Wide Studio Home
Up to
  ## Class Name WSCvdb ## Specification of methods ### open Function Description Form long open(char* hostname,char* username,char* passwd,char* dbname,char* port) Function Connect to a database Description Connect to a database via ODBC Parameters
  (in)char* hostname | Specify a hostname
  (in)char* username | Specify a user name to connect
  (in)char* passwd | Specify the password
  (in)char* dbname | Specify a database name
  (in)char* port | Specify a port number by strings

dbname, port are used when PostgreSQL is used. When using odbc, hostname should should dsn and dbname, port should be omitted or specify NULL
Return value
  WS_NO_ERR: Success, WS_ERR: Fail
Notice
  None
Samples

           long ret = newvdb__000->open("10.20.30.1","user","passwd","dbname","5432");
           if (ret == WS_NO_ERR){
             //Connected
           }else{
             //Connection failed, obtaining an error message
             char buffer[1024];
             newvdb__000->getErrorMsg(buffer,1024);
           }

  ### open Function Description

  Form
    long open()
  Function
    Connect to a database
  Description
    Connect to a database using a property values
  Parameters
    None
  Return value
    WS_NO_ERR: Success, WS_ERR: Fail
  Notice
    None
  Samples

             long ret = newvdb__000->open();
             if (ret == WS_NO_ERR){
               //Connected...
             }else{
               //Connection failed, obtaining an error message
               char buffer[1024];
               newvdb__000->getErrorMsg(buffer,1024);
             }

  ### close Function Description

  Form
    long close()
  Function
    Disconnect from a database
  Description
    Disconnect from a database via ODBC
  Parameters
    None
  Return value
    WS_NO_ERR: Success, WS_ERR: Fail
  Notice
    None
  Samples

             long ret = newvdb__000->close();
             if (ret == WS_NO_ERR){
               //Discconnected
             }else{
               //Disconnection failed, obtaining an error message
               char buffer[1024];
               newvdb__000->getErrorMsg(buffer,1024);
             }

  ### isOpen Function Description

  Form
    WSCbool isOpen()
  Function
    Obtain a status of dabase connection
  Description
    Obtain a status of dabase connection via ODBC
  Parameters
    None
  Return value
    True: Connected to database,False: not connected.
  Notice
    None
  Samples

             WSCbool ret = newvdb__000->isOpen();
             if (ret == False){
               //No connection
             }else{
               //Connecting
             }

  ### sqlExecute Function Description

  Form
    long sqlExecute(const char* sql)
  Function
    Issue a SQL sentence against a database
  Description
    Issue a SQL sentence against a database via ODBC
  Parameters

    (in)const char* sql | Specify a SQL sentence

  Return value
    WS_NO_ERR: Success, WS_ERR: Fail
  Notice
    The data obtained by issuing SQL sentences can be accessed using WSCdbRecord class
  Samples

          //Create a table and store data
          char buf1[1024];
          strcpy(buf1, "drop table shinamono");
          long ret = newvdb__000->sqlExecute(buf1);
          strcpy(buf1,"create table shinamono(code int, hinmei char(20), nedan float)");
          newvdb__000->sqlExecute(buf1);
          newvdb__000->beginTran();
          strcpy(buf1,"insert into shinamono values(1, 'Orange', 100)");
          newvdb__000->sqlExecute(buf1);
          strcpy(buf1,"insert into shinamono values(2, 'Apple', 200)");
          newvdb__000->sqlExecute(buf1);
          strcpy(buf1,"insert into shinamono values(3, 'Banana', 300)");
          newvdb__000->sqlExecute(buf1);
          strcpy(buf1,"insert into shinamono values(4, 'Melon', 0)");
          newvdb__000->sqlExecute(buf1);
          newvdb__000->commitTran();

          //Refer to a data
          WSCdbRecord rs(newvdb__000);
          char var[256];
          WSCstring result;
          newvdb__000->beginTran();
          if(rs.open("select * from shinamono order by code") == WS_NO_ERR) {
            while (!rs.isEOF()) {
              rs.getColValue("code", &var);
              int code = (int)var;
              result << "code:" << (int)var << " ";
              rs.getColValue("hinmei", &var);
              result << "hinmei:" << (char*)var << " ";
              rs.getColValue("nedan", &var);
              char buf[80];
              double nedan = (float)var + 10;
              sprintf(buf, "%f", (float)var);
              result << "nedan:" << buf << "\n";
            }
            printf("result:\n%s",(char*)result);
          }

  ### beginTran Function Description

  Form
    long beginTran()
  Function
    Start transaction
  Description
    Start transaction using ODBC
  Parameters
    None
  Return value
    WS_NO_ERR: Success, WS_ERR: Fail
  Notice
    Database should be connected beferhand
  Samples

             long ret = newvdb__000->beginTran();
             if (ret == WS_NO_ERR){
               //Transaction successfull
             }else{
               //Transaction failed, obtaining an error message
               char buffer[1024];
               newvdb__000->getErrorMsg(buffer,1024);
             }

  ### commitTran Function Description

  Form
    long commitTran()
  Function
    Commit transaction
  Description
    Commit transaction via ODBC
  Parameters
    None
  Return value
    WS_NO_ERR: Success, WS_ERR: Fail
  Notice
    Database should be connected beforehand
  Samples

             long ret = newvdb__000->commitTran();
             if (ret == WS_NO_ERR){
               //Transaction commit successfull
             }else{
               //Transaction commit failed, obtaining an error message
               char buffer[1024];
               newvdb__000->getErrorMsg(buffer,1024);
             }

  ### abortTran Function Description

  Form
    long abortTran()
  Function
    Abort transaction
  Description
    Abort transaction using ODBC
  Parameters
    None.
  Return value
    WS_NO_ERR: Success, WS_ERR: Fail
  Notice
    Transaction should be started beforehand
  Samples

             long ret = newvdb__000->abortTran();
             if (ret == WS_NO_ERR){
               //Transaction abortion successful
             }else{
               //Transaction abortion failed, obtaining an error message
               char buffer[1024];
               newvdb__000->getErrorMsg(buffer,1024);
             }

  ### getErrorMsg Function Description

  Form
    long getErrorMsg(char* buffer,long buflen)
  Function
    Obtain error strings
  Description
  Parameters

    (in/out)char* buf | Buffer to store error strings
    (in)long buflen | Buffer length

  Return value
    None.
  Notice
  Samples
    Refer to open sample

  Document Release 3.20
  For use with Wide Studio Release 3.20, Spring 2003

  Wide Studio Home | Up to

  Copyright(C) T. Hirabayashi, 1999-2003 |  | Last modified: February 3, 2003