Sample 1 (toys.csl)

C Scripting Language
Reference Manual
Version 4.4.0

<< Back  End  Next >>
 
 
INDEX
Introduction
Installation
Using the CSL executive
Language
Directives
System library
String library
Math library
Regular expression lib.
File library
Database library
   daxCheckCursor
   daxCommit
   daxConnect
   daxDatabase
   daxDisconnect
   daxDispose
   daxDone
   daxFetch
   daxLiteral
   daxParse
   daxRollback
   daxRowsProcessed
   daxSelectColumnName
   daxSelectColumns
   daxSelectColumnSize
   daxSelectColumnType
   daxSimple
   daxSupply
   Sample 1 (toys.csl)
   Sample 2 (portable.csl)
   Sample 3 (unknown.csl)
Async Communication
Registry/Profile handling
Windows control
C API
C++ Class Interface
CSL links
  

This is an example using several dax functions. Take a userid, password and connection that is available on your system.

#loadLibrary 'ZcSysLib'
#loadLibrary 'ZcStrLib'
#loadLibrary 'ZcDaxLib'
 
main()
{
  // check arguments
  if (sizeof(mainArgVals) < 3) {
    const exc[3] = {
      'usage  : csl toys name/password@connection',
      ' ',
      'example: csl toys SCOTT/TIGER@SALES'
    };
    throw exc;
  }
 
  sysLog('connect');
  var name, pass, conn, a = 2;
  name = strSplitConnectString(mainArgVals[a],pass,conn);
  var link = daxConnect('db2',conn,name,pass); // (*) (**)
 
  try {
    sysLog('drop old table');
    daxSimple(link, 'drop table csltest');
    daxCommit(link);
  }
  catch (var exc[]) {
    sysLog('no old table to drop');
  }
 
  daxSimple(link,
    'create table csltest ( '
       'ident integer, '        // (*)
       'descr varchar(30) '
    ')'
  );
 
  sysLog('insert rows');
  var toys = {
    1, 'barbie',
   12, 'football',
  325, 'tomb raider II',
   18, 'flipper'
  };
  var csr = daxParse(link,
              'insert into csltest(ident,descr) '
              'values (#, #30)'
            );
  daxSupply(csr,toys);
  daxDone(csr);
  daxDispose(csr);
  daxCommit(link);
 
  sysLog(
    '# of rows in csltest is '|
    daxSimple(link, 'select count(*) from csltest')
  );
 
  sysLog('query rows');
  csr = daxParse(link,
    'select ident, descr from csltest '
     'where ident between # and # '
     'order by ident'
  );
  var vals = { 10, 1000 };
  daxSupply(csr, vals);
  while (daxFetch(csr, vals))
    sysLog(vals[0]|' - '|vals[1]);
 
  sysLog('disconnect');
  daxDisconnect(link);
}

For ORACLE you would have to change the statements marked (*) to:

  var link = daxConnect('oracle',conn,name,pass);
  ...
  daxSimple(link,
    'create table csltest ( '
       'ident number(6), '
       'descr varchar2(30) '
    ')'
  );

For change to MYSQL you would only have to change line (**).

If you want to write database independent dax scripts have a closer look to the Sample 2 (Portable).

  Copyright © IBK Landquart Last revision: 27.05.2002 << Back  Top  Next >>