File: n_cst_db.sru
Size: 2519
Date: Sat, 08 Dec 2007 15:38:26 +0100
$PBExportHeader$n_cst_db.sru
$PBExportComments$Connects to SCLCA
forward
global type n_cst_db from nonvisualobject
end type
end forward

global type n_cst_db from nonvisualobject
end type
global n_cst_db n_cst_db

forward prototypes
public function long of_connect ()
public subroutine of_disconnect ()
public function integer of_connect (string as_dbsection)
end prototypes

public function long of_connect ();/* Connect to Database */
/* Override Function in descendant or use other method to connect */

// Profile EAS Demo DB V105
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit = False
SQLCA.DBParm = "ConnectString='DSN=EAS Demo DB V105;UID=dba;PWD=sql'"
CONNECT USING SQLCA;

/* Return sqlcode for Connect statement */
Return SQLCA.SQLCode


end function

public subroutine of_disconnect ();/* Disconnect from Database */
COMMIT USING SQLCA;
DISCONNECT USING SQLCA;
end subroutine

public function integer of_connect (string as_dbsection);string ls_DBINIFile

ls_DBINIFile = CGIEnv.of_getINIFileName( )

if FileExists (ls_DBINIFile) then
   SQLCA.DBMS        = ProfileString ( ls_DBINIFile,as_dbsection, "DBMS", "")
   SQLCA.Database    = ProfileString ( ls_DBINIFile,as_dbsection, "Database", "")
   SQLCA.UserId      = ProfileString ( ls_DBINIFile,as_dbsection, "UserID", "")
   SQLCA.DBPass      = ProfileString ( ls_DBINIFile, as_dbsection, "DBPass", "")
   SQLCA.LogId       = ProfileString ( ls_DBINIFile, as_dbsection, "LogID", "")
   SQLCA.LogPass     = ProfileString ( ls_DBINIFile, as_dbsection, "LogPassword",   "")
   SQLCA.ServerName  = ProfileString ( ls_DBINIFile,as_dbsection, "Servername",  "")
   SQLCA.DBParm      = ProfileString ( ls_DBINIFile,as_dbsection, "DBParm", "")
   SQLCA.Lock        = ProfileString ( ls_DBINIFile, as_dbsection, "Lock", "")
   SQLCA.AutoCommit  = (Pos(Lower(ProfileString ( as_dbsection, "Database", "Lock", "")),"true")=1)
end if

CONNECT USING SQLCA;

If SQLCA.SQLCode <> 0 Then
   log.of_addmessage( 9 ,  "SQLCA.DBMS: "       + SQLCA.DBMS )
   log.of_addmessage( 9 ,  "SQLCA.DBParm: "     + SQLCA.DBParm )
   log.of_addmessage( 9 ,  "SQLCA.ErrText: "    + SQLCA.SQLErrText )
   log.of_addmessage( 9 ,  "SQLCA.SQLDBCode: "  + String(SQLCA.SQLDBCode) )
   log.of_addmessage( 9 ,  "SQLCA.ErrText: "    + SQLCA.SQLErrText )
End If
/* Return sqlcode for Connect statement */
Return SQLCA.SQLCode 



end function

on n_cst_db.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_cst_db.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on