• Welcome, Guest. Please login.
June 19, 2019, 04:47:56 pm


Welcome to the SQLitening support forums!

Why not to use slSetProcessMods "E0"

Started by cj, March 27, 2015, 11:04:24 am

Previous topic - Next topic


March 27, 2015, 11:04:24 am Last Edit: March 27, 2015, 11:39:42 am by cj
If you make a syntax error in SQL or miss any error the program will continue without any mention of it usng "E0".

Now use slSetProcessMods "E2" so all errors are trapped and user can report them and abort or continue.

This code has an error that is not caught using slSetProcessMods "E0".
Should be 5 records returned. Left error in code for you to discover.

Return names alphabetically within highest to lowest balance.

Result should be:
5  KLUME     HEIDI     1000
4  SIMPSON   HOMER     1000
1  ZORRO     XAVIER    1000
3  SIMPSON   BART      999
2  SIMPSON   LISA      999

#COMPILE EXE  'Why not to use slGetProcessMods "E0"
#DIM ALL                                           'check variable assignments
$Ip         = ""                          'server ip on same machine or 192. or machine name
%PortNumber = 0                                    'use default port if 0 or actual port forwarded to by router
#INCLUDE "\sql\inc\sqlitening.inc"                 'sqlite include file routines
FUNCTION PBMAIN () AS LONG                         'program starting point using PowerBASIC
  LOCAL COLUMN,LastColumn AS LONG,sData AS STRING  'define variables
  slSetProcessMods "E2"                            'trap all errors, allow continue or abort
  'slConnect $IP,%PortNumber                       'optionally connect on remote server
  IF slGetErrorNumber THEN ? slGetError,,"Connect error":EXIT FUNCTION
  slOpen "Database.db3","C"                        'Open database or create if not exists
  slExe "drop table if exists clients"             'start fresh each time by dropping table, optional
  slExe "Create Table If Not Exists Clients(ClientID integer primary key autoincrement,LASTNAME,FIRSTNAME,BALANCE)"

  slExe "Create Index if Not Exists BalIndex  on Clients(BALANCE,LASTNAME,FIRSTNAME)"'index bal+lastname+firstname
  IF slGetErrorNumber THEN  ? slGetError,,"Create BalIndex Error":EXIT FUNCTION

  slexe "Insert into Clients values(NULL,'ZORRO', 'XAVIER',1000)"'insert highest balance and name
  slExe "Insert into Clients values(NULL,'SIMPSON','LISA',999 )" '
  slExe "Insert into Clients values(NULL,'SIMPSON','BART',999) " '
  slExe "Insert into Client  values(NULL,'SIMPSON','HOMER',1000)"

  slExe "Insert into Clients values(NULL,'KLUME','HEIDI',1000) "  '

  slSel "Select * FROM Clients order by BALANCE DESC,LASTNAME,FIRSTNAME"  'alphabetical by highest balance
  IF slGetErrorNumber THEN  ? slGetError,,"order by BALANCE":EXIT FUNCTION

  IF slGetRow THEN                                   'get first row or return message No data
    LastColumn = slGetColumnCount                    'number of columns
    DO                                               'while row exists loop
      FOR COLUMN  = 1 TO LastColumn                  '  column loop
        sData = sData + slf(COLUMN) + $TAB           '    combine columns
      NEXT                                           '  loop
      ASC(sdata,LEN(sData)) = 13                     '  change last tab on line to CR
    LOOP WHILE slGetRow                              'row loop

    MSGBOX sData,,"5 records alphabetical within highest balance"
  ELSE                                                '
    MSGBOX "No data",,EXE.NAME$                      'no recordset
' slDisconnect                                       'optional, suggested if using server


slSetProcessMods "E0"                            'trap all errors, always continue "E0"
slConnect $IP,%PortNumber                        'connect on remote server
IF slGetErrorNumber THEN                         'unable to connnect
  result = MSGBOX("Switch to local mode?",%MB_OKCANCEL,slGetError)
  IF result <> 1 THEN END                        'ok was not pressed, end program
  slSetProcessMods "L0"                          'switch ruts to local mode, required
slSetProcessMods "E2"                            'trap all errors, allow continue or abort