Page tree
Skip to end of metadata
Go to start of metadata

The following example assumes that there are defined the objects SD.DbStruct, TB.DTable. Then the particular process D2000 DBManager must be started and a database with the particular DSN name must be correctly configured in the operating system.

INT _handle ; handle for access to the database
 INT _retCode
 TEXT _where
 RECORD (SD.DbStruct)_dbRow ; artificial variables
 RECORD (SD.DbStruct) _dbRowSave 
 
 ; open the table to modify 
 DB_CONNECT TB.Table, _DB_MODIFY, _handle, _retCode
 IF _retCode # _ERR_NO_ERROR THEN ; cannot connect to the database table
     END
 ENDIF 
 
 ; reading according to key value
 _dbRow[1]^Int := 1
 DB_READ _handle, _dbRow[1], _retCode
 IF _retCode # _ERR_NO_ERROR THEN ; row not found
     END
 ENDIF 
 
 ; assign the original database table row to the artificial variable
 SET _dbRowSave[1] WITH _dbRow[1] ; change text
 _dbRow[1]^Text := _dbRow[1]^Text + "change" 
 ; update the database table row according to the key value
 DB_UPDATE _handle, _dbRow[1], _retCode
 IF _retCode # _ERR_NO_ERROR THEN ; unsuccessful update
     END
 ENDIF 
 
 ; read the row again, but using WHERE clausule
 _where := "Int="+%IToStr(_dbRowSave[1]^Int)
 DB_READ _handle, _dbRow[1], _retCode WHERE _where
 IF _retCode # _ERR_NO_ERROR THEN ; there must be 
     END
 ENDIF 
 
 ; read the row again, but using WHERE clausule and parametrized condition
 _where := "Int= #PAR#"
 DB_READ _handle, _dbRow[1], _retCode WHERE _where BINDIN _dbRowSave[1]^Int
 IF _retCode # _ERR_NO_ERROR THEN ; there must be 
     END
 ENDIF 
 
 ; delete it
 DB_DELETE _handle, _dbRow[1], _retCode
 IF _retCode # _ERR_NO_ERROR THEN ; there must be
     END
 ENDIF 
 
 ; or using WHERE clausule
 ;_where := "Int="+%IToStr(_dbRowSave[1]^Int)
 ;DB_DELETE _handle, __retCode WHERE _where
 ;IF _retCode # _ERR_NO_ERROR THEN ; there must be
 ; END
 ;ENDIF
 
 ; or using WHERE clausule and parametrized condition
 ;_where := "Int=#PAR#"
 ;DB_DELETE _handle, __retCode WHERE _where BINDIN _dbRowSave[1]^Int
 ;IF _retCode # _ERR_NO_ERROR THEN ; there must be
 ; END
 ;ENDIF
 
 ; insert the orginal content 
 DB_INSERT _handle, _dbRowSave[1], _retCode
 IF _retCode # _ERR_NO_ERROR THEN ; it should be successful
     END
 ENDIF 
 
 ; close the database table
 DB_DISCONNECT _handle

The following example assumes, that there are defined the objects SD.BlobStruct, TB.BlobTable. Then corresponding DBManager process must be running and the database with corresponding DSN name must be correctly configured. Except the column ID and Name (defined in SD.BlobStruct), the database table BlobTable in the database must also contains the column MyFile of BLOB type (Binary Large OBject). Sybase database this type calls LONG BINARY, Oracle it calls BLOB and MS SQL Server calls it IMAGE.

INT _handle ; handle for access to the database table
 INT _retCode
TEXT _where
RECORD (SD.BlobStruct)_dbRow ; auxiliary variable

; open the datanase table for modification 
DB_CONNECT TB.BlobTable, _DB_MODIFY, _handle, _retCode
IF _retCode # _ERR_NO_ERROR THEN ; cannot connect the database table
    END
ENDIF 
; insert a row into the database table
 _dbRow^ID := 99
_dbRow^Meno := "My inserted file"
 DB_INSERT _handle, _dbRow, _retCode
 IF _retCode # _ERR_NO_ERROR THEN ; it should be successful
     END
 ENDIF 

; insert the file as a BLOB object into the database table
DB_UPDATE_BLOB _handle, "MyFile", "C:\File99.txt", _retCode, 99
 IF _retCode # _ERR_NO_ERROR THEN ; it should be successful
    END
ENDIF 

 ; read another file (from the row with ID=11) from the table and save it to the disk C:\
DB_READ_BLOB _handle, "MyFile", "C:\File11_new.txt", _retCode, 11

 ; if the column ID of the structure definition is not defined
; as a key, it is neccessary to define the WHERE condition:
 DB_READ_BLOB _handle, "MyFile", "C:\File11_new.txt", _retCode WHERE "ID=11"
 
 ; close the database table
 DB_DISCONNECT _handle
; -- work with no need to open the database table (DBS_ functions)

; read another file without opening the database table
 DBS_READ_BLOB TB.BlobTable, "MyFile", "C:\File22_new.txt", _retCode, 22

; save it to the database table
DBS_UPDATE_BLOB TB.BlobTable, "MyFile", "C:\File22_new.txt", _retCode, 33
 

Related pages:

Write a comment…