Combination View Flat View Tree View
Threads [ Previous | Next ]
Usage of ado2Odbc.dll
2/7/17 3:32 PM

I try to connect to a Oracle 11 or 12 database using the details from here:

I don't think the AdoOdbcConnect Operation is working. Is there any documentation for the correct parameters? E.g. port and host?
Debug seems not to work with CALL.

Any ideas or links to hidden documentation?


RE: Usage of ado2Odbc.dll
12/11/17 10:20 AM as a reply to Swante.
In the example under the used Ports are: IP-address: Port:8080 Username:testuser Password:testpass

ADOxx has standard functionality for reading text files. 
The contents of files can be read using the command call FREAD from the "AdoScript" messageport.
The syntax of the command call is:

1CC "AdoScript" FREAD file: filename [ binary: boolValue ] [ base64: boolValue ] .
2--> RESULT ecode: intValue text: strValue .
You can read the contents of a text file in a string variable using the above command call and then parse the resulting text according to its format and your needs.

In the example below, the text file contains a list of <name>:<value> pairs separated by a blank space (" ") representing the configuration for a fictive server, also attached to this post

1IP-address: Port:8080 Username:testuser Password:testpass

The following code snippet reads the contents of the file and saves the values of the respective attributes of an object:

 1CC "Core" GET_ATTR_VAL objid: (idMyObjID) attrname: ("Configuration File")
 2     # --> RESULT ecode: intValue val: strValue
 4CC "AdoScript" FREAD file: ( val )
 5 # --> RESULT ecode: intValue text: strValue .
 6SET sTxtData: ( text )
 8FOR sParameter in: (sTxtData) sep: " " {
 9    SET sName: (token(sParameter,0,":"))
10    SET sValue: (token(sParameter,1,":"))
11    CC "Core" SET_ATTR_VAL objid: (idMyObjID) attrname: (sName) val: (sValue)
12     # --> RESULT ecode: intValue

The example above assumes that the object ID has been determined beforehand and set to the variable "idMyObjID" and the parameter names in the text file are the exact names of the attributes (IP-address,  Port, Username, Password)

If the text file has a CSV-format, the rows are separated by the charracter "\n" and within a row, the columns are separated by ";". As an example, the following CSV data can be read in the string variable sCsvData and then parsed line by line:


 1CC "AdoScript" FREAD file: ("sample.csv")
 2# --> RESULT ecode: intValue text: strValue .
 3SET sCsvData: ( text )
 5SET nRow:0
 6SET nColumn:0
 7FOR sRow in: (sCsvData) sep: "\n" {
 8  SET nColumn:0
 9  FOR sCell in: (sRow) sep: ";" {
10    CC "AdoScript" INFOBOX ("Row: " + STR nRow + ", Column: " + STR nColumn + ", Value: " + sCell)
11    SET nColumn: (nColumn + 1)   
12  }
13  SET nRow: (nRow + 1)
The example above does not update the model, but reads the file and provides INFOBOX output. This output can be replaced by SET_ATTR_VAL statements to update objects for each line.

If the data is stored in XLS files, it can be accessed by using the command CALL for calling functions stored in the DLL file "ado2Xls.dll". The DLL file is included in the ADOxx 1.3 UL1 package and can be found in the folder <ADOxx_folder>\tools\misc\ .
The function AdoXslFetchText is used for reading the data from an XSL file. The function AdoXslCloseAll() is used for closing all XSL files previously opened for reading withe the function AdoXlsFetchText.

 1SET sDLLpath: ("tools\\misc\\ado2Xls.dll")
 2SET sXSLfile: ("C:\\Temp\\test.xls")
 3SET sXSLsheet: ("T1")
 4SET sXSLcell: ("2,2")
 6CALL dll: (sDLLpath) function:"long AdoXlsFetchText( char *strsource, char *strcell, char **pstrtext )"
 7              strsource: (sXSLfile + ">" + sXSLsheet) strcell: (sXSLcell)
 9CC "AdoScript" INFOBOX ("The value of the cell located at row 2, column 2 in the sheet T2 is: " + pstrtext)
11CALL dll: (sDLLpath) function:"long AdoXlsFetch( char *strsource, char *strcell, char **pstrvalue )"
12              strsource: (sXSLfile + ">" + sXSLsheet) strcell: (sXSLcell)
14CALL dll: (sDLLpath) function:"long AdoXlsCloseAll()"

If the data is stored in a database, it can be read using the functions stored in the DLL file "ado2Odbc.dll", also included in the ADOxx 1.3 UL1 package and located in the folder <ADOxx_folder>\tools\misc\ .
Since the communication with the server is a bit more complex than reading from a file, several functions are required:
AdoOdbcConnect   - for connecting to the database
AdoOdbcFetch     - for reading a single value from the database
AdoOdbcExecute   - for executing a query that returns more than one value
AdoOdbcFetchNext - for retrieving the next data record from the database; is always used after calling the AdoOdbcExecute function

 1SET sDLLpath: ("tools\\misc\\ado2Odbc.dll")
 2SET sODBCconnection: "testdb"
 3SET sODBCusername: "testuser"
 4SET sODBCpass: "testpass"
 6CALL dll: (sDLLpath) function:"long AdoOdbcConnect( char *strdbparam, char **pstrdbinst )"
 7        strdbparam: (sODBCconnection + " " + sODBCusername + " " + sODBCpass)
 8SETL sDbHandle: (pstrdbinst)
10SET sSelect: ("SELECT ID, Name, address FROM testdb01 WHERE ID>1")
12CALL dll: (sDLLpath) function:"long AdoOdbcFetch( char *strdbinst, char *strselect, char **pstrresult )"
13        strdbinst: (sDbHandle) strselect: (sSelect)
14#Only returns the first cell from the first row resulting from the SELECT statement       
16CALL dll: (sDLLpath) function:"long AdoOdbcExecute( char *strdbinst, char *strselect, char **pstrcolumns )"
17              strdbinst: (sDbHandle)
18              strselect: (sSelect)
19              # --> pstrcolumns (list of column names separated by ASCII #128)
21SET eCode:0
22SET sResults:""
23WHILE ( eCode = 0 ) {
24    CALL dll: (sDLLpath) function:"long AdoOdbcFetchNext( char *strdbinst, long bmaskresult, char **pstrresult )"
25        strdbinst: (sDbHandle) bmaskresult:0
26     # --> pstrresult
27    SET eCode: ( result )
28    SET sResults: (sResults + "\n" + pstrresult)
31CC "AdoScript" EDITBOX text: (sResults) title: "Results..."
33CALL dll: (sDLLpath) function:"long AdoOdbcClose( char *strdbinst )"
34          strdbinst: (sDbHandle)

RE: Usage of ado2Odbc.dll
10/16/19 1:26 AM as a reply to Swante.
Did you succeed in the connection?