ODBCsock version 1.0 by Olivier Auverlot (olivier.auverlot@free.fr) The ODBCsock protocol is a TCP client protocol allowing Suneido to communicate with the program package ODBCSocketServer (http://odbcsock.sourceforge.net) who is available for Microsoft Windows 9x and Windows 2000. It implements a gateway to an ODBC data source using an XML based protocol. The client sends a request coded in XML to the ODBC Socket Server, which connects to the ODBC data source and returns the result to the client. This protocol is particularly well adapted to requests for small amounts of information from a data base. Indeed, the coding in XML of the result considerably increases its size. Moreover, Odbc Socket Server does not support multiple requests within one transaction: the connection is initialized and destroyed for each request. NOTE: You must have an ODBC database and ODBCSocketServer installed and running before you can use this interface. METHODS OdbcSockClient(odbcsock_server, dsn = false, user = false, password = false, format = 0, cdata = false, timeout = 60, port = 9628) This method establishes a connection with the server on which the Odbc Socket Server service is running. The general options are: * the name or the IP address of the server * the name of the ODBC data source * the login for the connection (false if not used) * the password for the connection * the format of XMS file generated by the server (0,1 or 2) * whether or not to use Cdata (boolean) * the maximum waiting time (in seconds) * the TCP port for the connection The general options format and cdata must correspond to those indicated in the registry of the server running the Odbc Socket Server service. This method returns a connection instance that is used for the other methods. SetSecureMode(mode) Activate or deactivate the secure mode of the protocol. If mode is true, only the SQL requests containing Select instructions will be authorized to run. SetDataConversion(mode) Activate or deactivate automatic data conversion. By default, all the values are represented in the form of character strings. If this mode is true, the protocol tries to convert the strings into a numbers or dates. DoSQL(sql_string) Carry out an SQL request and return a boolean value according to the failure or the success of the operation. conn = OdbcSockClient("192.168.0.248",dsn="mybase","mylogin","mypwd",0,cdata=true); if conn.DoSQL('delete from matable where colonne="test"') == true Print("Ok !"); else Print("Failure !"); conn.Close(); ExecSQL(sql_string, §block) Carry out an SQL request. The result is returned in the form of a record selection (record). conn = OdbcSockClient("192.168.0.248",dsn="mybase","mylogin","mypwd",0,cdata=true); conn.ExecSQL('select * from matable') { | rec | Print(rec) } conn.Close() ReadXML(sql_string) Carry out an SQL request. The result is returned in XML format. This method is useful for format 1 (Msdtd) not managed by the protocol. conn = OdbcSockClient("192.168.0.248",dsn="mybase","mylogin","mypwd",0,cdata=true); response = conn.ReadXML('select count(*) from matable') Print(response) conn.Close() SaveToTable(sqlRequest, tableName, keyName, keyGen = false) Carry out an SQL request. The result is stored in a Suneido table that is automatically created. If the table already exists, it is destroyed before importating the data. The primary key is provided by the KeyName general options. If this key does not exist, the KeyGen arguments start the automate generation of one value using the Timestamp() instruction. This method return a boolean value according to the success or the failure of the import. conn = OdbcSockClient("192.168.0.248",dsn="mybase","mylogin","mypwd",0,cdata=true); conn.SetDataConversion(true); res = conn.SaveToTable("select * from mytable","mycopy","key") conn.Close() GetColumnsNames() Returns an object containing a list of the columns. This instruction can only be used following ExecSQL(), ReadXML() or SaveToTable(). Close() Close the connection with the ODBC Socket Server service.