[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gambas-devel
Subject:    Re: [Gambas-devel] Change to gb.db.odbc to use ODBC Connection Strings.
From:       ML <d4t4full () gmail ! com>
Date:       2015-08-28 11:21:18
Message-ID: 55E0442E.4040209 () gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


*On 2015-08-27 15:06, Benoît Minisini wrote:*
> *Le 27/08/2015 20:03, Benoît Minisini a écrit :*
>> *Le 27/08/2015 19:14, zxMarce a écrit :*
>>> Benoît,
>>> No problem, I know you're not the author of the ODBC component.
>>> Precisely, one of my modifications was adding an IF to call either 
>>> SQLConnect (normal method so far) or SQLDriverConnect; this is the 
>>> new call, and does not use .User, .Password nor .Name, as they can 
>>> all be set in the connection string.
>>> I added, then, an IF and a FUNCTION. This is the IF, in main.c's 
>>> open_database:
>>> ... And this is the function that new IF calls:
>>> Thanks,
>>> zxMarce.
>> Please post directly to the developer mailing-list. nabble.com makes 
>> your mail unreadable by removing pictures.
>> Or don't post pictures. Post the code as text!
> If your function (is_host_a_connstring) returns a boolean value, you 
> can use 'bool' as return datatype.
> If you are testing a boolean value, writing that:
>     if (xxx == TRUE)
> is not needed. Just write:
>     if (xxx)
> Regards,
Wow! I did not know Nabble removed text blocks from mails. I now also 
see the missing segments in my mails. I used 'Raw Text' blocks to post 
the code.
Anyway, for post completeness, the missing if was as follows:

     if (is_host_a_connstring(desc->host) == TRUE)
     {
         /* zxMarce: Connect to Database (desc->host is an ODBC 
Connection String) */
         retcode = SQLDriverConnect(odbc->odbcHandle, 0, (SQLCHAR *) 
desc->host, SQL_NTS, 0, 0, 0, SQL_DRIVER_NOPROMPT);
         /* Example - ODBC-ConnString, all one line (must assign this to 
the Connection.Host property in
            Gambas code and then call Connection.Open):
"Driver=<driverSectionNameInODBCInst.Ini>;
                          TDS_Version=<useNormally'7.2';
                          Server=<serverNameOrIP>;
                          Port=<serverTcpPort>;
                          Database=<defaultDatabase>;
                          UId=<userName>;
                          Pwd=<password>>"
         */
     } else {
         /* Connect to Database (desc->host is an ODBC Data Source Name) */
         retcode = SQLConnect(odbc->odbcHandle, (SQLCHAR *) desc->host, 
SQL_NTS, (SQLCHAR *) desc->user, SQL_NTS, (SQLCHAR *) desc->password, 
SQL_NTS);
     }

And the missing helper function was:

     /*
     Internal function to check if the .Host property is actually an 
ODBC connection string.
     ODBC ConnStrings have one or more "ParamName=ParamValue" pairs, 
delimited by semicolons.
     The function helps the component know whether to call SQLConnect 
(when a host/DSN),
     or SQLDriverConnect (when a ConnString).
     zxMarce, 20150814
     */
     static int is_host_a_connstring(char *host_or_cs)
     {

       int length = strlen(host_or_cs);
       bool connstrCharFound = FALSE;
       int counter;
       char curChar;

       for (counter = 0; counter < length; counter++)
       {
         curChar = host_or_cs[counter];
         if ((curChar == '=') | (curChar == ';'))
         {
           connstrCharFound = TRUE;
           break;
         }
       }

       return connstrCharFound;

     }

Now I will change the function type from INT to BOOL and reform the IF. 
Thanks for the tip!

Regards,

[Attachment #5 (text/html)]

<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <b>On 2015-08-27 15:06, Benoît Minisini wrote:</b><br>
    <blockquote cite="mid:55DF51B8.6060706@users.sourceforge.net"
      type="cite"><b>Le 27/08/2015 20:03, Benoît Minisini a écrit :</b>
      <blockquote type="cite"><b>Le 27/08/2015 19:14, zxMarce a écrit :</b>
        <blockquote type="cite">Benoît,<br>
          No problem, I know you're not the author of the ODBC
          component.<br>
          Precisely, one of my modifications was adding an IF to call
          either SQLConnect (normal method so far) or SQLDriverConnect;
          this is the new call, and does not use .User, .Password nor
          .Name, as they can all be set in the connection string.<br>
          I added, then, an IF and a FUNCTION. This is the IF, in
          main.c's open_database:<br>
          ... And this is the function that new IF calls:<br>
          Thanks,<br>
          zxMarce.</blockquote>
        Please post directly to the developer mailing-list. nabble.com
        makes your mail unreadable by removing pictures.<br>
        Or don't post pictures. Post the code as text!</blockquote>
      If your function (is_host_a_connstring) returns a boolean value,
      you can use 'bool' as return datatype.<br>
      If you are testing a boolean value, writing that:<br>
          if (xxx == TRUE)<br>
      is not needed. Just write:<br>
          if (xxx)<br>
      Regards,<br>
    </blockquote>
    Wow! I did not know Nabble removed text blocks from mails. I now
    also see the missing segments in my mails. I used 'Raw Text' blocks
    to post the code.<br>
    Anyway, for post completeness, the missing if was as follows:<br>
    <br>
    <tt>    if (is_host_a_connstring(desc-&gt;host) == TRUE)</tt><tt><br>
    </tt><tt>    {</tt><tt><br>
    </tt><tt>        /* zxMarce: Connect to Database (desc-&gt;host is
      an ODBC Connection String) */</tt><tt><br>
    </tt><tt>        retcode = SQLDriverConnect(odbc-&gt;odbcHandle, 0,
      (SQLCHAR *) desc-&gt;host, SQL_NTS, 0, 0, 0, SQL_DRIVER_NOPROMPT);</tt><tt><br>
    </tt><tt>        /* Example - ODBC-ConnString, all one line (must
      assign this to the Connection.Host property in </tt><tt><br>
    </tt><tt>           Gambas code and then call Connection.Open):</tt><tt><br>
    </tt><tt>                       
      "Driver=&lt;driverSectionNameInODBCInst.Ini&gt;;</tt><tt><br>
    </tt><tt>                         TDS_Version=&lt;useNormally'7.2';</tt><tt><br>
    </tt><tt>                         Server=&lt;serverNameOrIP&gt;;</tt><tt><br>
    </tt><tt>                         Port=&lt;serverTcpPort&gt;;</tt><tt><br>
    </tt><tt>                         Database=&lt;defaultDatabase&gt;;</tt><tt><br>
    </tt><tt>                         UId=&lt;userName&gt;;</tt><tt><br>
    </tt><tt>                         Pwd=&lt;password&gt;&gt;"</tt><tt><br>
    </tt><tt>        */</tt><tt><br>
    </tt><tt>    } else {</tt><tt><br>
    </tt><tt>        /* Connect to Database (desc-&gt;host is an ODBC
      Data Source Name) */</tt><tt><br>
    </tt><tt>        retcode = SQLConnect(odbc-&gt;odbcHandle, (SQLCHAR
      *) desc-&gt;host, SQL_NTS, (SQLCHAR *) desc-&gt;user, SQL_NTS,
      (SQLCHAR *) desc-&gt;password, SQL_NTS);</tt><tt><br>
    </tt><tt>    }</tt><tt><br>
    </tt><br>
    And the missing helper function was:<br>
    <br>
    <tt>    /* </tt><tt><br>
    </tt><tt>    Internal function to check if the .Host property is
      actually an ODBC connection string.</tt><tt><br>
    </tt><tt>    ODBC ConnStrings have one or more
      "ParamName=ParamValue" pairs, delimited by semicolons.</tt><tt><br>
    </tt><tt>    The function helps the component know whether to call
      SQLConnect (when a host/DSN), </tt><tt><br>
    </tt><tt>    or SQLDriverConnect (when a ConnString).</tt><tt><br>
    </tt><tt>    zxMarce, 20150814</tt><tt><br>
    </tt><tt>    */</tt><tt><br>
    </tt><tt>    static int is_host_a_connstring(char *host_or_cs)</tt><tt><br>
    </tt><tt>    {</tt><tt><br>
    </tt><tt>    </tt><tt><br>
    </tt><tt>      int length = strlen(host_or_cs);</tt><tt><br>
    </tt><tt>      bool connstrCharFound = FALSE;</tt><tt><br>
    </tt><tt>      int counter;</tt><tt><br>
    </tt><tt>      char curChar;</tt><tt><br>
    </tt><tt>    </tt><tt><br>
    </tt><tt>      for (counter = 0; counter &lt; length; counter++)</tt><tt><br>
    </tt><tt>      {</tt><tt><br>
    </tt><tt>        curChar = host_or_cs[counter];</tt><tt><br>
    </tt><tt>        if ((curChar == '=') | (curChar == ';'))</tt><tt><br>
    </tt><tt>        {</tt><tt><br>
    </tt><tt>          connstrCharFound = TRUE;</tt><tt><br>
    </tt><tt>          break;</tt><tt><br>
    </tt><tt>        }</tt><tt><br>
    </tt><tt>      }</tt><tt><br>
    </tt><tt>    </tt><tt><br>
    </tt><tt>      return connstrCharFound;</tt><tt><br>
    </tt><tt>    </tt><tt><br>
    </tt><tt>    }</tt><br>
    <br>
    Now I will change the function type from INT to BOOL and reform the
    IF. Thanks for the tip!<br>
    <br>
    Regards,<br>
  </body>
</html>


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


_______________________________________________
Gambas-devel mailing list
Gambas-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic