head	1.1;
access;
symbols
	REL-09_01_0200:1.1
	REL-09_01_0100:1.1
	REL-09_00_0310:1.1
	REL-09_00_0300:1.1
	REL-09_00_0200:1.1
	REL-09_00_0101:1.1
	REL-09_00_0100:1.1
	REL-08_04_0200:1.1
	REL-08_04_0100:1.1
	REL-08_03_0400:1.1
	REL-08_03_0300:1.1
	REL-08_03_0200:1.1
	REL-08_03_0100:1.1
	REL-08_02_0500:1.1
	REL-08_02_0400:1.1
	REL-08_02_0300:1.1
	REL-08_02_0200:1.1
	REL-08_02_0100:1.1
	REL8_1_STABLE:1.1.0.2
	REL-08_01_0200:1.1
	REL-08_01_0102:1.1
	REL-08_01_0101:1.1
	REL-08_01_0100:1.1
	REL-08_01_0006:1.1
	REL-08_01_0005:1.1
	REL-08_01_0004:1.1;
locks; strict;
comment	@# @;


1.1
date	2005.08.27.19.44.47;	author dpage;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Move docs into the source tree.
@
text
@<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    <title>psqlODBC HOWTO - Ch</title>
  </HEAD>

  <body bgcolor="#ffffff" text="#000000" link="#ff0000" vlink="#a00000" alink="#0000ff">
  
<h1>psqlODBC HOWTO - Ch</h1>

<p>

<i>
Author: Wayne Cheng  (wayne@@softintegration.com)<br>
Release Date: 23 September 2003<br>
Description: Example based Mini-Howto on Accessing PostgreSQL from Ch
</i>
<br><br>
Ch is a C/C++ interpreter from <a href="http://www.softintegration.com">http://www.softintegration.com</a>.<br>
It is designed for cross-platform scripting, shell programming, 
2D/3D plotting, numerical computing, and embedded scripting. 

<br><br>
Requirements to get the code to work:

<br>
<ul>
<li>Ch Standard Edition or Professional Edition</li>
<li>Ch ODBC Toolkit.</li>
<li>IODBC, UNIXODBC or Microsoft ODBC manager.</li>
<li>A PostgreSQL datasource.</li>
</ul>

<b>How to run ODBC code in Ch</b><br>
You should be able to use the simple.c scripts, start Ch shell first.

<br>
<blockquote>
<pre>
% ch
                                   Ch 
                  Standard edition, version 4.0.0.11291 
              (C) Copyright 2001-2003 SoftIntegration, Inc.
                     http://www.softintegration.com
/home/wcheng> cd $CHHOME/package/iodbc/demos
/usr/local/ch/package/iodbc/demos&gt; ls
odbctest.c  simple.c
/usr/local/ch/package/iodbc/demos&gt; ./simple.c
SQLAllocHandle() OK
SQLSetEnvAttr() ok
SQLAllocHandle() ok
SQLSetConnectAttr() ok
/usr/local/ch/package/iodbc/demos&gt; cat simple.c

/**************************** simple.c *****************************/ 
#include &lt;sqlext.h&gt;
#include &lt;stdio.h&gt;

void ODBC_error (       /* Get and print ODBC error messages */
    SQLHENV henv,       /* ODBC Environment */
    SQLHDBC hdbc,       /* ODBC Connection Handle */
    SQLHSTMT hstmt)     /* ODBC SQL Handle */
{
    UCHAR   sqlstate[10];
    UCHAR   errmsg[SQL_MAX_MESSAGE_LENGTH];
    SDWORD  nativeerr;
    SWORD   actualmsglen;
    RETCODE rc = SQL_SUCCESS;

    while ( rc != SQL_NO_DATA_FOUND)
    {
        rc = SQLError(henv, hdbc, hstmt,
                      sqlstate, &nativeerr, errmsg,
                      SQL_MAX_MESSAGE_LENGTH - 1, &actualmsglen);
                     
         if (rc == SQL_ERROR) {
              printf ("SQLError failed!\n");
              return;
         }

         if (rc != SQL_NO_DATA_FOUND) {
               printf ("SQLSTATE = %s\n", sqlstate);
               printf ("NATIVE ERROR = %d\n", nativeerr);
               errmsg[actualmsglen] = '\0';
               printf ("MSG = %s\n\n", errmsg);
          }
     }
     if (hdbc != SQL_NULL_HDBC)
     {
        SQLFreeHandle (SQL_HANDLE_DBC, hdbc);
     }
     if (henv != SQL_NULL_HENV)
     {
        SQLFreeHandle (SQL_HANDLE_ENV, henv);
     }
}

int main(void)
{
    SQLHENV henv = SQL_NULL_HENV;
    SQLHDBC hdbc = SQL_NULL_HDBC;
    SQLHSTMT hstmt = SQL_NULL_HSTMT;
    RETCODE  rc    = SQL_SUCCESS;

    rc = SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);

    if (rc != SQL_ERROR)
    {
        printf("SQLAllocHandle() OK\n");
        rc = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3,0);
        if (rc != SQL_ERROR)
        {
            printf("SQLSetEnvAttr() ok\n");
            rc = SQLAllocHandle (SQL_HANDLE_DBC, henv, &hdbc);
            if ( rc != SQL_ERROR)
            {
                 printf("SQLAllocHandle() ok\n");
                 rc = SQLSetConnectAttr(hdbc, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF,0);
                 if (rc != SQL_ERROR)
                 {
                       printf("SQLSetConnectAttr() ok\n");
                       SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
                       SQLFreeHandle(SQL_HANDLE_ENV, henv);
                 }
             }
         }
     }

     if (rc == SQL_ERROR)
     {
         ODBC_error (henv, hdbc, hstmt);
     }
}

</pre>

</body>
</html>@
