public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: odbc driver problem
@ 2002-06-04  4:11 Ignasi Villagrasa
  0 siblings, 0 replies; 3+ messages in thread
From: Ignasi Villagrasa @ 2002-06-04  4:11 UTC (permalink / raw)
  To: cygwin

Thanks for answering at first, Pavel.

I have been trying to detail the problem preparing several tests.

I've tested the following c program:

odbc.c:


#include <windows.h>
#include <sql.h>
#include <sqlext.h>



int main()
{
    SQLHENV    henv;
    SQLHDBC    hdbc;
    SQLHSTMT   hstmt;
    SQLRETURN  retcode;
    char buf[1024];
    char CamposConsulta[256];
    unsigned char sqlstate[15];
    short ncol, cont = 0, i;
    long buflen, nrow;
    UWORD Functions[100];


    retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
    if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
    {
       retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, 
(SQLPOINTER)SQL_OV_ODBC2, 0);
       if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
       {
          retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
          if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
          {
             //retcode = SQLGetFunctions(hdbc, SQL_API_SQLCONNECT, 
Functions);

             retcode = SQLConnect(hdbc, (SQLCHAR*) "sample-MCODBC", 
SQL_NTS, NULL, 0, NULL, 0);

              /*
                  *  Obtener errores de conexión
                  */
                if (retcode)
                {
                  if (SQLError (henv, hdbc, SQL_NULL_HSTMT, sqlstate, 
NULL, buf, sizeof(buf), NULL) == SQL_SUCCESS)
                {
                      printf ("%s, SQLSTATE=%s\n", buf, sqlstate);
                }
             }
             else printf ("\nConexión establecida\n");

             if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
             {
                retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
                if (retcode == SQL_SUCCESS || retcode == 
SQL_SUCCESS_WITH_INFO)
                {
                    retcode = SQLAllocStmt(hdbc, &hstmt);

                    sprintf(CamposConsulta, 
"PRENUMORD,PRETAR,PREPROD,PREFEC,PREHOR,PREDENS,PREVOLTOT,PREDES1,PREDES2,PREDES3,PRECANSEC1,PRECANSEC2,PRECANSEC3,PRECANSEC4,PRECANSEC5,PRECANSEC6");
                     sprintf(buf, "SELECT %s FROM preconfiguraciones 
WHERE PRECLI > 0", CamposConsulta);
                    retcode = SQLExecDirect(hstmt, (UCHAR *)buf, 
strlen(buf));

                    if (!retcode)
                        printf ("\nEjecución de frase correcta\n");

                    retcode = SQLNumResultCols(hstmt, &ncol);

                    while(!retcode)
                    {
                        retcode = SQLFetch(hstmt);
                        if (retcode)
                        {
                              if (SQLError (henv, hdbc, SQL_NULL_HSTMT, 
sqlstate, NULL, buf, sizeof(buf), NULL) == SQL_SUCCESS)
                            {
                                  printf (    "%s, SQLSTATE=%s\n", buf, 
sqlstate);
                            }
                        }
                        else
                        {
                            printf ("\nRecuperado registro\n");
                            for (i = 1; i <= ncol; i++)
                            {
                                retcode = SQLGetData(hstmt, i, 
SQL_C_DEFAULT, buf, 100, &buflen);
                                printf ("\nCampo  %d: %s\n", i, buf);
                            }
                        }
                        cont++;
                    }

                   SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
                }
                SQLDisconnect(hdbc);
                printf ("\nDesconexión realizada\n");
             }
             SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
          }
       }
    }
    SQLFreeHandle(SQL_HANDLE_ENV, henv);
}


1) First test

The first compilation is as follows:


gcc -o odbc.exe odbc.c -lmcodbcnt

Previously I generated a libmcodbcnt.a file using following line:

DLLTOOL --dllname mcodbcnt.dll --def libmcodbcnt.def --output-lib 
libmcodbcnt.a

mcodbcnt.dll is the odbc driver I'm testing and libmcodbcnt.def contents 
are:

DESCRIPTION 'MCASE ODBC Driver'
EXPORTS
SQLAllocHandle@12
SQLSetEnvAttr@16
SQLError@32
SQLFetch@4
SQLGetData@24
SQLConnect@28
SQLAllocStmt@8
SQLExecDirect@12
SQLNumResultCols@8
SQLFreeHandle@8
SQLDisconnect@4
SQLFreeStmt@8


Aditionally, I included a message Box as the first instruction of 
SqlConnect to check that dll is working properly.
When I run odbc.exe I get the proper messageBox telling me the program 
is running  SqlConnect function.


2) Second  test

When I try to test dll file as an odbc driver:

- I install mcodbcnt.dll as an odbc driver. I have installation routines 
for the driver and sample-data sources. After this process I can see 
mcodbc driver an data source in Windows ODBC Administration tool. (Or in 
Windows Register).
- I run 'gcc -o odbc.exe odbc.c -lodbc32' linking to odbc32 instead of 
mcodbcnt .

Then I get when calling SqlConnect:

0 [main] odbc 868 handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
4934 [main] odbc 868 open_stackdumpfile: Dumping stack trace to 
odbc.exe.stackdump

And odbc.exe.stackdump is:

Exception: STATUS_ACCESS_VIOLATION at eip=1A4599A2
eax=00000000 ebx=000003E9 ecx=00000000 edx=00000000 esi=00911748 
edi=00911764
ebp=0022F5D8 esp=0022F5A4 program=S:\MC\BPAA\odbc.exe
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
Stack trace:
Frame     Function  Args
0022F5D8  1A4599A2  (1A459E11, 00000000, 1A456E50, 784629C0)
0022F618  1A459E96  (00000000, 0022F648, 1A45BDAC, 009117F0)
0022F658  1A45BDDE  (00911764, 009112F8, 00911748, 00911250)
0022F6B4  1A45BE59  (00911764, 009112F8, 009112F8, 0022F6F8)
009112F8  1F7E3D0E  (00000000, 00000000, 00000000, 00000000)
  47443 [main] odbc 868 handle_exceptions: Exception: 
STATUS_ACCESS_VIOLATION
  48345 [main] odbc 868 handle_exceptions: Error while dumping state 
(probably corrupted stack)


It finds SqlConnect (The message I sent last week didn't and a IM001 
message appeared). It didn't find SqlConnect because .def was wrong. It 
was my mistake. Now it finds the function but fails. It doesn't arrive 
at MessageBox. And that's the first instruccion into the driver. 
Obviously I suppose is not a problem to run MessageBox into my odbc driver.


3) Third test.


I try the to compile odbc.c against MySql 2.5 odbc driver. I change the 
data source to be attached.

I call

    retcode = SQLConnect(hdbc, (SQLCHAR*) "test", SQL_NTS, NULL, 0, 
NULL, 0);

instead of

    retcode = SQLConnect(hdbc, (SQLCHAR*) "sample-MCODBC", SQL_NTS, 
NULL, 0, NULL, 0);

and test is a data source for MySql odbc driver.

I compile gcc -o odbc.exe odbc.c -lodbc32

I test it and it works properly.

-----------------------------------------------------------------------------------------------------------------------------------

So there's something I'm going wrong using mcodbcnt.dll as a odbc driver.
There's no odbc syntax problem in odbc.c because gcc compiles it and it 
works fine using MySql.
The dll is properly built because the program finds the entry points 
when directly attached. So there's a problem when using odbc32.dll 
between odbc.exe and mcodbcnt.dll. I don't know if it's a compile 
options issue or if it's a necesary odbc step I'm not following.

Could anyone help me ?

Thanks in advance. Ignasi Villagrasa.
 












--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: odbc driver problem
  2002-06-03  2:24 Ignasi Villagrasa
@ 2002-06-03  3:51 ` Pavel Tsekov
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Tsekov @ 2002-06-03  3:51 UTC (permalink / raw)
  To: Ignasi Villagrasa; +Cc: cygwin

Hello Ignasi,

Monday, June 03, 2002, 11:24:22 AM, you wrote:

IV> I'm trying to compile an odbc driver using cygwin compiler.

IV> All seems to work properly, but when trying to link sqlconnect from odbc 
IV> sdk test application an error appears telling me the driver doesn't have 
IV> the sqlconnect function.

Are you saying that you try to link the application to the driver dll
? I don't think this is the right think to do... You have to link with
the driver manager and call the driver through various functions
exported from the driver manager dll.

IV> That's very strange because I can link directly the dll from a C 
IV> application without using odbc manager. So I think perhaps odbc manager 
IV> is looking for an special calling convention I'm not aware.

The odbc.dll exports two entries for some of its functions - one for
the Unicode version and one for the ASCII version. The Unicode version
functions use the following naming convention FunctionNameW, while the
ASCII one use FunctionNameA. So if you're trying to load dynamically
(LoadLibrary) the SQLConnect function you have to specify the proper
name for the function you want to use. If you are linking at compile time
the header files for ODBC (and other windows headers) take care for
you to link against the proper version.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* odbc driver problem
@ 2002-06-03  2:24 Ignasi Villagrasa
  2002-06-03  3:51 ` Pavel Tsekov
  0 siblings, 1 reply; 3+ messages in thread
From: Ignasi Villagrasa @ 2002-06-03  2:24 UTC (permalink / raw)
  To: cygwin

Hi everyone,

I'm trying to compile an odbc driver using cygwin compiler.

All seems to work properly, but when trying to link sqlconnect from odbc 
sdk test application an error appears telling me the driver doesn't have 
the sqlconnect function.

That's very strange because I can link directly the dll from a C 
application without using odbc manager. So I think perhaps odbc manager 
is looking for an special calling convention I'm not aware.

Could anyone help me ?

Thanks in advance.

Ignasi Villagrasa.









--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-06-04 11:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-04  4:11 odbc driver problem Ignasi Villagrasa
  -- strict thread matches above, loose matches on Subject: below --
2002-06-03  2:24 Ignasi Villagrasa
2002-06-03  3:51 ` Pavel Tsekov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).