Re: GetColAtrribute() with SQL_DESC_OCTET_LENGTH parameter

From: Robert Sundström (robert_at_nnoossppaamm.mimer.se)
Date: 06/04/04

  • Next message: Paulpap: "Cannot configure ODBC"
    Date: Fri, 04 Jun 2004 09:53:43 +0200
    
    

    On Sun, 30 May 2004 21:06:03 -0700, Ritesh <riteshp@ihatespam.webyog.com>
    wrote:
    > In my application, I am connecting to various RBDMS but primarily SQL
    > Server and MySQL using ODBC 3.0 driver. In SQL Server, if I execute
    > SQLCollAtrribute with SQL_DESC_OCTET_LENGTH, it is returning me the
    > maximum number of bytes that the column can have irrespective of whether
    > the column in the resultset has that much data or not.
    >
    > Whereas, the MySQL ODBC driver is returning the maximum data that a
    > column has for that particular resultset.
    >
    > Why is the anomaly? Does this information differ from driver to driver.

    Both products probably return correct values as long as it is the case
    that no string value ever returned on the column is longer than what
    SQL_DESC_OCTET_LENGTH has specified. Note that this has nothing to do with
    the underlying table column. For instance, if you do:

    create table A(C1 character varying(50))

    select substring(C1 from 40) from A

    In this particular case, no column value will ever be longer than 10
    characters, and the value of SQL_DESC_OCTET_LENGTH might reflect that.

    > Is there any way to know the size of a perticular row in raw-bytes
    > before doing an SQLFetch(). I would like to allocate the memory before I
    > do SQLFetch(). Looking into Google Groups it seems that many people have
    > the same problem but not much solution has been provided.

    Don't bind the column and use SQLGetData to obtain the column value.
    SQLGetData always return the number bytes left to return (StrLen_or_Ind
    parameter). So, start calling SQLGetData with a buffer length of 0, and
    you'll get the size of the data in wherever StrLen_or_Ind is pointing at.

    > What is the best way to know how much bytes the RDBMS takes in the disk
    > to store that much information?

    No. That cannot be done using the ODBC API.

    -- 
    Robert Sundström, Mimer SQL Development
    Mimer Information Technology AB, http://www.mimer.com
    Validate your SQL statements/procedures at 
    http://developer.mimer.com/parser
    

  • Next message: Paulpap: "Cannot configure ODBC"

    Relevant Pages

    • Re: SQL using C
      ... I am almost a new C programmer and now I need to use SQL within my C ... The people who are telling you to use a C API are out of their mind. ... MySQL + PHP), then the MySQL C API is a rather good option to get ... Because ODBC is extremely well documented. ...
      (comp.lang.c)
    • Re: CLSQL - feature request?
      ... WH> For ODBC, it's not really important as the actual back end ODBC ... WH> driver does all of the work for the DB anyway, ... WH> essentially recreating the complete SQL ASCII statement for each ... Recreating an SQL statement is not always possible due to the maximum length ...
      (comp.lang.lisp)
    • ODBC Errors In Query
      ... I normally use MySQL with PHP, but I'm delving into connecting to Access ... with ODBC, ... First, if I add an ORDER BY clause, so the query looks like this: ... $sql = "select tblScores.FullName, sumas TotalPoints ...
      (comp.lang.php)
    • Re: ODBC MySQL driver porting to Microsoft SQL
      ... the driver at all. ... > Hi I am trying to port a MySQL database to microsoft SQL server 2000. ... > downloaded the mysql odbc driver, ...
      (microsoft.public.data.odbc)
    • Re: Log to MySQL
      ... > MySQL or you set up the MySQL database and tables using MS ... > SQL Stored Procedures. ... >>The Microsoft Web Proxy failed to log information to ODBC ...
      (microsoft.public.isa)