Re: Postgresql ODBC driver not found

2021-09-26 Thread Henning Follmann
On Sun, Sep 26, 2021 at 12:10:39AM +0200, Pierre Couderc wrote:
> 
> On 9/25/21 3:46 PM, Henning Follmann wrote:
> > 
> > have you tried to use the odbc lib from unixodbc instead of
> > libiodbc?
> > 
> 
> I think you are right on many other points...
> 
> But particularly on this one !
> 
> I did remove libodbc2-dev and install unixodbc-dev and now it is OK...!!
> 
> Wow !
> 
> Thank you very much.
> 
> Let us have a Sunday without any odbc...
> 
> PC
>


I am glad this worked out.
Now I wonder if we should file a bug report against the lib?


-H

-- 
Henning Follmann   | hfollm...@itcfollmann.com



Re: Postgresql ODBC driver not found

2021-09-25 Thread Pierre Couderc



On 9/25/21 3:46 PM, Henning Follmann wrote:


have you tried to use the odbc lib from unixodbc instead of
libiodbc?



I think you are right on many other points...

But particularly on this one !

I did remove libodbc2-dev and install unixodbc-dev and now it is OK...!!

Wow !

Thank you very much.

Let us have a Sunday without any odbc...

PC



Re: Postgresql ODBC driver not found

2021-09-25 Thread Henning Follmann
On Sat, Sep 25, 2021 at 09:16:33AM +0200, Pierre Couderc wrote:
> 
> On 9/24/21 5:31 PM, Henning Follmann wrote:
> > 
> > and I see you do not do any error checking.
> > This would be a first step to find out where it fails.
> > 
> > I added some code...
> > 
> 
> You hare fully right, I have corrected, but I have the same result and no
> more idea.. :

I do not have much time this weekend, but I will try to set up my
computer to reproduce your setup  - maybe on Monday ...

In the meanwhile a few thoughts,
have you tried to use the odbc lib from unixodbc instead of
libiodbc?

Another thing I have myself no clue but, what happens if you do
not set the odbc version?

And just one thought about your loop:

try
do {
/* in there look at SQLSTATE
   for anything other than SQL_SUCCESS
   I am concerned that SQL_NO_DATA is
   not a reliable break indicator */



}while (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO)

> 
> nous@pcouderc:~/projets//build$ ./ttest
> D  0.0:ln 19:main(): Start  : Compile time : Sep 25 2021 09:03:28
> 
> 0x55cee70a5ed0
> 
> 
> 
> nous@pcouderc:~/projets//build$ cat ../main.cpp
> #include 
> #include 
> #include 
> #pragma GCC diagnostic ignored "-Wendif-labels"
> #pragma GCC diagnostic ignored "-Wwrite-strings"
> 
> 
> #define TDBG clock_t ttdbg=clock();float
> ftdbg=((float)ttdbg)/CLOCKS_PER_SEC;
> #define DBG_(fmt, args...) {TDBG fprintf(stdout,string( string("D%5.1f:ln
> %d:%s(): ")+fmt).c_str(),ftdbg,__LINE__, __func__, ##args);fflush(stdout);}
> 
> using namespace std;
> extern "C"
> {
> #include 
> #include 
> }
> int main(int argc, char **argv)
> {
>     DBG_("Start  : Compile time : " __DATE__" " __TIME__"\n");
>     SQLHENV env;
>     SQLCHAR driver[256];
>     SQLCHAR attr[256];
>     SQLSMALLINT driver_ret;
>     SQLSMALLINT attr_ret;
>     SQLUSMALLINT direction;
>     SQLRETURN ret;
> 
>     ret=SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, );
>     if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) {
>         cerr << "Failed to allocate handle" << endl;
>         return -1;
>     }
>     ret=SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
>     if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) {
>         cerr << "Failed SQLSetEnvAttr" << endl;
>         return -1;
>     }
>     cout << env<     direction = SQL_FETCH_FIRST;
>     while(1)
>     {
>     ret = SQLDrivers(env, direction,
>                 driver, sizeof(driver),
> _ret,
>                 attr, sizeof(attr), _ret);
>         if(ret==SQL_NO_DATA) break;
>         printf("%s - %s\n", driver, attr);
>         if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata truncation\n");
>         direction = SQL_FETCH_NEXT;
>     }
>     return 0;
> }
> 
> 
> 


Have a nice weekend.
-H

-- 
Henning Follmann   | hfollm...@itcfollmann.com



Re: Postgresql ODBC driver not found

2021-09-25 Thread Pierre Couderc



On 9/24/21 5:31 PM, Henning Follmann wrote:


and I see you do not do any error checking.
This would be a first step to find out where it fails.

I added some code...



You hare fully right, I have corrected, but I have the same result and 
no more idea.. :


nous@pcouderc:~/projets//build$ ./ttest
D  0.0:ln 19:main(): Start  : Compile time : Sep 25 2021 09:03:28

0x55cee70a5ed0



nous@pcouderc:~/projets//build$ cat ../main.cpp
#include 
#include 
#include 
#pragma GCC diagnostic ignored "-Wendif-labels"
#pragma GCC diagnostic ignored "-Wwrite-strings"


#define TDBG clock_t ttdbg=clock();float 
ftdbg=((float)ttdbg)/CLOCKS_PER_SEC;
#define DBG_(fmt, args...) {TDBG fprintf(stdout,string( 
string("D%5.1f:ln %d:%s(): ")+fmt).c_str(),ftdbg,__LINE__, __func__, 
##args);fflush(stdout);}


using namespace std;
extern "C"
{
#include 
#include 
}
int main(int argc, char **argv)
{
    DBG_("Start  : Compile time : " __DATE__" " __TIME__"\n");
    SQLHENV env;
    SQLCHAR driver[256];
    SQLCHAR attr[256];
    SQLSMALLINT driver_ret;
    SQLSMALLINT attr_ret;
    SQLUSMALLINT direction;
    SQLRETURN ret;

    ret=SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, );
    if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) {
        cerr << "Failed to allocate handle" << endl;
        return -1;
    }
    ret=SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) 
SQL_OV_ODBC3, 0);

    if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) {
        cerr << "Failed SQLSetEnvAttr" << endl;
        return -1;
    }
    cout << env<                driver, sizeof(driver), 
_ret,

                attr, sizeof(attr), _ret);
        if(ret==SQL_NO_DATA) break;
        printf("%s - %s\n", driver, attr);
        if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata 
truncation\n");

        direction = SQL_FETCH_NEXT;
    }
    return 0;
}





Re: Postgresql ODBC driver not found

2021-09-24 Thread Henning Follmann
On Thu, Sep 23, 2021 at 11:55:00PM +0200, Pierre Couderc wrote:
> Thenk you, Henning, thank you Gregory .
> 
> On 9/23/21 5:49 PM, Gregory Seidman wrote:
> > On Thu, Sep 23, 2021 at 08:18:45AM -0400, Henning Follmann wrote:
> > > 
> > I don't see where you ask for the PostgreSQL ODBC connection in particular.
> > Maybe I'm the one missing something?
> You are right, I am not trying to connect (not soon) but trying to get the
> list of available drivers !
> > 
> > > isql "PostgreSQL Unicode"  
> > > 
> > > and perform a minimum check like:
> > > select 1;
> > 
> SQL> select 1
> ++
> | ?column?   |
> ++
> | 1  |
> ++
> SQLRowCount returns 1
> 1 rows fetched
> 
> SQL> quit
> 
> 
> unixodbc seems to work...

yes

> 
> I put here the full c++ source and the full result :
>

and I see you do not do any error checking.
This would be a first step to find out where it fails.

I added some code...

> 
> #include 
> #include 
> #include 
> #pragma GCC diagnostic ignored "-Wendif-labels"
> #pragma GCC diagnostic ignored "-Wwrite-strings"
> 
> #define TDBG clock_t ttdbg=clock();float
> ftdbg=((float)ttdbg)/CLOCKS_PER_SEC;
> #define DBG_(fmt, args...) {TDBG fprintf(stdout,string( string("D%5.1f:ln
> %d:%s(): ")+fmt).c_str(),ftdbg,__LINE__, __func__, ##args);fflush(stdout);}
> 
> using namespace std;
> extern "C"
> {
> #include 
> #include 
> }
> int main(int argc, char **argv)
> {
>     DBG_("Start  : Compile time :  __DATE__ __TIME__\n");
>     SQLHENV env;
>     SQLCHAR driver[256];
>     SQLCHAR attr[256];
>     SQLSMALLINT driver_ret;
>     SQLSMALLINT attr_ret;
>     SQLUSMALLINT direction;
>     SQLRETURN ret;
>
   ret = 
>     SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, );
   if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) { {
   /* most likely the odbc env is not set up properly
  write error message and bail */
  cerr << "Failed to allocate handle" << endl;
  return -1;
  }

  ret =
>     SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
  /* again, even this function is not guaranteed to succeed
 test ! */
> 
>     cout << env<     direction = SQL_FETCH_FIRST;

/* again here you just use the return value for your loop
   I think it might be helpful to test for SQL_SUCCESS and
   in case it fails to actually handle the error
   for error codes check:
   
https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqldrivers-function?view=sql-server-ver15
   */
   
>     while(SQL_SUCCEEDED (ret = SQLDrivers(env, direction,
>                 driver, sizeof(driver),
> _ret,
>                 attr, sizeof(attr), _ret)))
> {
>         direction = SQL_FETCH_NEXT;
>         printf("%s - %s\n", driver, attr);
>         if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata truncation\n");
>     }
>     return 0;
> }
> 
> 
> Result :
> 
> nous@pcouderc:~/projets//build$ ./ttest
> D  0.0:ln 33:main(): Start  : Compile time :  __DATE__ __TIME__
> 0x55b0948ffed0
> nous@pcouderc:~/projets//build$
> 
> and meson.build for completeness :
> 
> project('ttest','cpp', default_options : ['cpp_std=c++17'],
>     version : '0.1')
> cpp = meson.get_compiler('cpp')
> libiodbc_dep = cpp.find_library('libiodbc')
> incdirs = include_directories('/usr/include/iodbc')
> executable('ttest', 'main.cpp', dependencies : [libiodbc_dep],
> include_directories : incdirs)
> 
> 
> 

-- 
Henning Follmann   | hfollm...@itcfollmann.com



Re: Postgresql ODBC driver not found

2021-09-23 Thread Pierre Couderc

Thenk you, Henning, thank you Gregory .

On 9/23/21 5:49 PM, Gregory Seidman wrote:

On Thu, Sep 23, 2021 at 08:18:45AM -0400, Henning Follmann wrote:



I don't see where you ask for the PostgreSQL ODBC connection in particular.
Maybe I'm the one missing something?
You are right, I am not trying to connect (not soon) but trying to get 
the list of available drivers !
   


isql "PostgreSQL Unicode"  

and perform a minimum check like:
select 1;



SQL> select 1
++
| ?column?   |
++
| 1  |
++
SQLRowCount returns 1
1 rows fetched

SQL> quit


unixodbc seems to work...

I put here the full c++ source and the full result :


#include 
#include 
#include 
#pragma GCC diagnostic ignored "-Wendif-labels"
#pragma GCC diagnostic ignored "-Wwrite-strings"

#define TDBG clock_t ttdbg=clock();float 
ftdbg=((float)ttdbg)/CLOCKS_PER_SEC;
#define DBG_(fmt, args...) {TDBG fprintf(stdout,string( 
string("D%5.1f:ln %d:%s(): ")+fmt).c_str(),ftdbg,__LINE__, __func__, 
##args);fflush(stdout);}


using namespace std;
extern "C"
{
#include 
#include 
}
int main(int argc, char **argv)
{
    DBG_("Start  : Compile time :  __DATE__ __TIME__\n");
    SQLHENV env;
    SQLCHAR driver[256];
    SQLCHAR attr[256];
    SQLSMALLINT driver_ret;
    SQLSMALLINT attr_ret;
    SQLUSMALLINT direction;
    SQLRETURN ret;

    SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, );
    SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);

    cout << env<                driver, sizeof(driver), 
_ret,
                attr, sizeof(attr), 
_ret))) {

        direction = SQL_FETCH_NEXT;
        printf("%s - %s\n", driver, attr);
        if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata 
truncation\n");

    }
    return 0;
}


Result :

nous@pcouderc:~/projets//build$ ./ttest
D  0.0:ln 33:main(): Start  : Compile time :  __DATE__ __TIME__
0x55b0948ffed0
nous@pcouderc:~/projets//build$

and meson.build for completeness :

project('ttest','cpp', default_options : ['cpp_std=c++17'],
    version : '0.1')
cpp = meson.get_compiler('cpp')
libiodbc_dep = cpp.find_library('libiodbc')
incdirs = include_directories('/usr/include/iodbc')
executable('ttest', 'main.cpp', dependencies : [libiodbc_dep], 
include_directories : incdirs)






Re: Postgresql ODBC driver not found

2021-09-23 Thread Gregory Seidman
On Thu, Sep 23, 2021 at 08:18:45AM -0400, Henning Follmann wrote:
> On Thu, Sep 23, 2021 at 08:44:42AM +0200, Pierre Couderc wrote:
> > Thank you very much!
> > 
> > See below :
> > 
> > On 9/22/21 3:37 PM, Henning Follmann wrote:
> > > On Wed, Sep 22, 2021 at 11:07:28AM +0200, Pierre Couderc wrote:
> > > > It is here I see it/them with:
> > > > 
> > > > odbcinst -q -d
> > > > 
> > > > but not with :
> > > > 
> > > >    SQLHENV env;
> > > >    SQLCHAR driver[256];
> > > >    SQLCHAR attr[256];
> > > >    SQLSMALLINT driver_ret;
> > > >    SQLSMALLINT attr_ret;
> > > >    SQLUSMALLINT direction;
> > > >    SQLRETURN ret;
> > > >    SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, );
> > > >    SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
> > > > 
> > > >    direction = SQL_FETCH_FIRST;
> > > >    while(SQL_SUCCEEDED(ret = SQLDrivers(env, direction,
> > > >     driver, sizeof(driver), 
> > > > _ret,
> > > >     attr, sizeof(attr), 
> > > > _ret))) {
> > > >      direction = SQL_FETCH_NEXT;
> > > >      printf("%s - %s\n", driver, attr);
> > > >      if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata truncation\n");
> > > >    }
> > > > 
> > > > What do I miss...?

I don't see where you ask for the PostgreSQL ODBC connection in particular.
Maybe I'm the one missing something?

> > > The ability to clearly describe your problem!
> > Sorry I tried to be minimum... But here are more details?
> 
> Not sorry, but what do you expect? That everybody has a magic crystal
> bowl to fill in missing information?

Hey, ease up. Missing information makes it harder to diagnose the issue,
but there is no need to be rude about it.

[...]
> > >Did you compile it? And if so, how?
> > Yes, with default tools (gcc under debian bulllseye linked with libodbc)
> 
> Are you kidding me? That is not additional information. Just you
> being condescending.
> Strike one.
> 
> > >You installed odbcunix I assume.
> > >How did you configure it?
> > Correctly.
> 
> Really? REALLY?
> Strike two.

Wow, seriously rude.

[...]
> can you please connect to your database with:
> 
> isql "PostgreSQL Unicode"  
> 
> and perform a minimum check like:
> select 1;
[...]

That's helpful, and I look forward to seeing the response to this.

> -H
> 
> -- 
> Henning Follmann   | hfollm...@itcfollmann.com

--Gregory



Re: Postgresql ODBC driver not found

2021-09-23 Thread Henning Follmann
On Thu, Sep 23, 2021 at 08:44:42AM +0200, Pierre Couderc wrote:
> Thank you very much!
> 
> See below :
> 
> On 9/22/21 3:37 PM, Henning Follmann wrote:
> > On Wed, Sep 22, 2021 at 11:07:28AM +0200, Pierre Couderc wrote:
> > > It is here I see it/them with:
> > > 
> > > odbcinst -q -d
> > > 
> > > but not with :
> > > 
> > >    SQLHENV env;
> > >    SQLCHAR driver[256];
> > >    SQLCHAR attr[256];
> > >    SQLSMALLINT driver_ret;
> > >    SQLSMALLINT attr_ret;
> > >    SQLUSMALLINT direction;
> > >    SQLRETURN ret;
> > >    SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, );
> > >    SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
> > > 
> > >    direction = SQL_FETCH_FIRST;
> > >    while(SQL_SUCCEEDED(ret = SQLDrivers(env, direction,
> > >     driver, sizeof(driver), 
> > > _ret,
> > >     attr, sizeof(attr), _ret))) {
> > >      direction = SQL_FETCH_NEXT;
> > >      printf("%s - %s\n", driver, attr);
> > >      if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata truncation\n");
> > >    }
> > > 
> > > What do I miss...?
> > > 
> > The ability to clearly describe your problem!
> Sorry I tried to be minimum... But here are more details?

Not sorry, but what do you expect? That everybody has a magic crystal bowl to
fill in missing information?

> > 
> > What did you do?
> >I assume you wrote some c code.
> Yes, this  code above is written in c (c++ in fact but I have simplified).

That is not c code. This does not compile.
Provide a minimum example which compiles, at least.


> >Did you compile it? And if so, how?
> Yes, with default tools (gcc under debian bulllseye linked with libodbc)

Are you kidding me? That is not additional information. Just you
being condescending.
Strike one.

> >You installed odbcunix I assume.
> >How did you configure it?
> Correctly.

Really? REALLY?
Strike two.

> >What is the output of "odbcinst -q -d"?
> 
> Correct :
> 
> [PostgreSQL ANSI]
> [PostgreSQL Unicode]
>

all right that is something.

can you please connect to your database with:

isql "PostgreSQL Unicode"  

and perform a minimum check like:
select 1;


> > What did you expect?
> That my c program produces the same list
> > 
> > What did not work?
> >   Include logs, error messages.
> 
> Logs and error messages : none (This is the heart of the problem)
> 
> > 
> > What did you do to solve your problem so far?
> > 
> I have reduced my problem - which is much more complex - to the simplest
> test prograam.
> 
> And I ask for help, as I have no more idea after many hours.
> 
>

You know this is a debian user mailing list, right?

but anyway...


-H

-- 
Henning Follmann   | hfollm...@itcfollmann.com



Re: Postgresql ODBC driver not found

2021-09-23 Thread Pierre Couderc

Thank you very much!

See below :

On 9/22/21 3:37 PM, Henning Follmann wrote:

On Wed, Sep 22, 2021 at 11:07:28AM +0200, Pierre Couderc wrote:

It is here I see it/them with:

odbcinst -q -d

but not with :

   SQLHENV env;
   SQLCHAR driver[256];
   SQLCHAR attr[256];
   SQLSMALLINT driver_ret;
   SQLSMALLINT attr_ret;
   SQLUSMALLINT direction;
   SQLRETURN ret;
   SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, );
   SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);

   direction = SQL_FETCH_FIRST;
   while(SQL_SUCCEEDED(ret = SQLDrivers(env, direction,
    driver, sizeof(driver), _ret,
    attr, sizeof(attr), _ret))) {
     direction = SQL_FETCH_NEXT;
     printf("%s - %s\n", driver, attr);
     if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata truncation\n");
   }

What do I miss...?


The ability to clearly describe your problem!

Sorry I tried to be minimum... But here are more details?


What did you do?
   I assume you wrote some c code.

Yes, this  code above is written in c (c++ in fact but I have simplified).

   Did you compile it? And if so, how?

Yes, with default tools (gcc under debian bulllseye linked with libodbc)

   You installed odbcunix I assume.
   How did you configure it?

Correctly.

   What is the output of "odbcinst -q -d"?


Correct :

[PostgreSQL ANSI]
[PostgreSQL Unicode]


What did you expect?

That my c program produces the same list


What did not work?
  Include logs, error messages.


Logs and error messages : none (This is the heart of the problem)



What did you do to solve your problem so far?

I have reduced my problem - which is much more complex - to the simplest 
test prograam.


And I ask for help, as I have no more idea after many hours.




Re: Postgresql ODBC driver not found

2021-09-22 Thread Henning Follmann
On Wed, Sep 22, 2021 at 11:07:28AM +0200, Pierre Couderc wrote:
> It is here I see it/them with:
> 
> odbcinst -q -d
> 
> but not with :
> 
>   SQLHENV env;
>   SQLCHAR driver[256];
>   SQLCHAR attr[256];
>   SQLSMALLINT driver_ret;
>   SQLSMALLINT attr_ret;
>   SQLUSMALLINT direction;
>   SQLRETURN ret;
>   SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, );
>   SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
> 
>   direction = SQL_FETCH_FIRST;
>   while(SQL_SUCCEEDED(ret = SQLDrivers(env, direction,
>    driver, sizeof(driver), _ret,
>    attr, sizeof(attr), _ret))) {
>     direction = SQL_FETCH_NEXT;
>     printf("%s - %s\n", driver, attr);
>     if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata truncation\n");
>   }
> 
> What do I miss...?
>

The ability to clearly describe your problem!

What did you do?
  I assume you wrote some c code.
  Did you compile it? And if so, how?
  You installed odbcunix I assume.
  How did you configure it?
  What is the output of "odbcinst -q -d"?

What did you expect?

What did not work?
 Include logs, error messages.

What did you do to solve your problem so far?

-H






-- 
Henning Follmann   | hfollm...@itcfollmann.com