Sample 3 (Unknown Table)

C Styled Script
Reference Manual

<< Back  End  Next >>
 
 
INDEX
Introduction
Installation
Using The CSS Executive
Language
Directives
System Library
String Library
Regular Expression Lib.
File Library
Database Library
   daxCommit
   daxConnect
   daxDatabase
   daxDisconnect
   daxDispose
   daxDone
   daxFetch
   daxParse
   daxRollback
   daxRowsProcessed
   daxSelectColumnName
   daxSelectColumns
   daxSelectColumnSize
   daxSelectColumnType
   daxSimple
   daxSupply
   Sample 1 (Toys)
   Sample 2 (Portable)
   Sample 3 (Unknown Table)
C API
C++ API
CSS Links
  

Example selecting an table with unknown column layout

#loadLibrary 'KcSysLib'
#loadLibrary 'KcStrLib'
#loadLibrary 'KcDaxLib'
 
main()
{
  // check arguments
  if (sizeof(mainArgVals) < 4) {
    const exc[3] = {
      'usage  : CSS UNKNOWN name/password@connection tablename',
      ' ',
      'example: CSS UNKNOWN SCOTT/TIGER@SALES EMP'
    };
    throw exc;
  }
 
  // connect
  var name, pass, conn, a = 2;
  name = strSplitConnectString(mainArgVals[a++],pass,conn);
  var lnk = daxConnect('db2',conn,name,pass);
 
  // start processing
  var csr = daxParse(lnk, 'select * from '|mainArgVals[a]|' order by 1');
  var cols = daxSelectColumns(csr);
  var line, size[cols];
 
  // display title
  for (var i=0; i<cols; i++) {
    size[i] = daxSelectColumnSize(csr,i);
    line |=
      strSubString(
        daxSelectColumnName(csr,i),
        1, size[i]+1
      );
  }
  sysLog(line);
 
  // underline title
  line = '';
  for (i=0; i<cols; i++)
    line |= strSubString('',1,size[i],'-')|' ';
  sysLog(line);
 
  // query and display the rows
  var col[cols];
  while (daxFetch(csr, col)) {
    line = '';
    for (i=0; i<cols; i++)
      line |= strSubString(col[i],1,size[i])|' ';
    sysLog(line);
  }
  sysLog();
  sysLog(daxRowsProcessed(csr)|' row(s) selected');
  daxDisconnect(lnk);
}

The ouput might look like this:

IDENT    DESCR
-------- ------------------------------
1        leather football
7        tennis racket
15       rollerblades
 
3 row(s) selected
 Copyright © IBK LandquartLast revised by Peter Koch, 24.02.00<< Back  Top  Next >>