Quantcast
Channel: Visual COBOL - Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4356

RE: Has anyone used embedded SQL with Postgresql in COBOL?

$
0
0

It might be possible to use OpenESQL with embedded SQL for this provider by either using a format 6 CONNECT statement or by opening a connection object directly and then using the EXEC ADO BIND CONNECTION statement prior to executing your EXEC SQL statements for the database.

The EXEC ADO BIND CONNECTION statement is documented here.

The following is an example of using the format 6 connect statement to connect to a mySQL database which does not have a connection DSN defined using the connection editor.

 

            ****************************************************************
            * Copyright (C) Micro Focus 2010-2013. All rights reserved.
            *
            * This sample code is supplied for demonstration purposes only
            * on an "as is" basis and is for use at your own risk.
            *
            ****************************************************************
              working-storage section.
            *  Include the SQL Communications Area. This includes the
            *  definitions of SQLCODE, etc
              EXEC SQL INCLUDE SQLCA END-EXEC.
              EXEC SQL BEGIN DECLARE SECTION END-EXEC
              01 connectionstring pic x(300) value spaces.
              01 namestring       pic x(35).
              01 countrycode      pic x(3).
              01 nametosearch     pic x(35).
              EXEC SQL END DECLARE SECTION END-EXEC
              procedure division.
            *  Connect to a data store.
TYPE6 *  The connectionstring host variable should be populated as
TYPE6 *  appropriate for the data source you wish to use.
TYPE6 *  For example, if using the Access data store as referenced
TYPE6 *  in the readme for this sample, uncomment the following
TYPE6 *  MOVE statement, ensuring that the path to DEMO.MDB is
TYPE6 *  correct for your environment:
TYPE6 * MOVE "Provider=Microsoft.Jet.OLEDB.4.0;Data Source"
TYPE6 * & "=""C:\Users\Public\Documents\Micro Focus\Visual COBOL"
TYPE6 * & " 2010\Samples\sql\openesql\SampleData\Access\DEMO.MDB"";"
TYPE6 * & "Persist Security Info=False;User ID=admin;"
TYPE6 * & "factory=System.Data.OleDb;"
TYPE6 *  TO connectionstring
TYPE6 *  If using Microsoft SQL Server, then :
TYPE6 *  1. If using Windows authentication, uncomment the
TYPE6 *  following MOVE statement, updating the :
TYPE6 *
TYPE6 *  Data Source parameter to be the name of your SQL Server
TYPE6 *  instance.
TYPE6 *
TYPE6 *  Initial Catalog parameter to point to the database you
TYPE6 *  wish to use.
TYPE6 *  MOVE "Data Source=(local);Initial Catalog=mydatabase;"
TYPE6 *  & "Integrated Security=True;MultipleActiveResultSets=True;"
TYPE6 *  & "MultipleActiveResultSets=True;"
TYPE6 *  & "factory=System.Data.SqlClient;" TO connectionstring
TYPE6 * 2. If using SQL Server authentication, uncomment the
TYPE6 * following MOVE statement, updating the :
TYPE6 *
TYPE6 *  Data Source parameter to be the name of your SQL Server
TYPE6 *  instance.
TYPE6 *
TYPE6 *  Initial Catalog parameter to point to the database you
TYPE6 *  wish to use.
TYPE6 *
TYPE6 *  User ID and Password to be the appropriate SQL Server
TYPE6 *  connection criteria for connection.
TYPE6 *  MOVE "Data Source=(local);Initial Catalog=mydatabase;"
TYPE6 *  & "User ID=myuser;Password=mypassword;"
TYPE6 *  & "MultipleActiveResultSets=True;"
TYPE6 *  & "factory=System.Data.SqlClient;" TO connectionstring
TYPE6 *  You may wish to uncomment the following verification
TYPE6 *  that the connectionstring host variable has been set
TYPE6 *  appropriately.
TYPE6 * if connectionstring = spaces
TYPE6 *   display " "
TYPE6 *   display "In order to execute this sample, connectionstring"
TYPE6 *    "needs to be populated"
TYPE6 *   display "with the appropriate connection criteria for your"
TYPE6 *   display "database. Update the source and rebuild."
TYPE6 *   goback
TYPE6 * end-if
TYPE6 *sample MySQL ADO.NET connection string
TYPE6 *refer to MySQL documentation for complete list of connection properties and appropriate values
TYPE6 *remember to include the factory property as shown (MySql.Data.MySqlClient).
TYPE6  MOVE "server=localhost;database=world;uid=root;password=yourpsw;factory=MySql.Data.MySqlClient;" TO connectionstring
TYPE6  EXEC SQL
TYPE6      connect using :connectionstring
TYPE6  END-EXEC
              if sqlcode not = 0
                   display "Error: cannot connect "
                   display sqlcode
                   display sqlerrmc
                   goback
             end-if
           *sample query to the world database included with MySQL installation
             MOVE 'Gaza' TO nametosearch
             EXEC SQL
                   SELECT  name,  countrycode
                         INTO   :namestring, :COUNTRYCODE
                         FROM city
                      WHERE name = :nametosearch
             END-EXEC
             DISPLAY namestring countrycode
             goback.

Viewing all articles
Browse latest Browse all 4356

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>