apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liuxulin <liuxu...@gmail.com>
Subject Re: About DBD Prepare Statement Problem
Date Thu, 28 Jan 2010 08:17:17 GMT
Hello everyone,
    Here i got some problems in APRU , hope for your helps.

    I modified the dbd/apr_dbd_mysql.c in function 
"dbd_mysql_pselect_inertnal"
    after code:
        ret = mysql_stmt_bind_result(statement->stmt, (*res)->bind);
    I add these two line:
        printf("mysql_stmt_bind_result ret: %d\n", ret);
        printf("(*res)->bind[0].buffer=%s \n", (*res)->bind[0].buffer);

    The result of first line is 0(zero), and the length of the buffer is 
also zero.

    Is the result rigth?


Thanks for your helps and replies!

My code is as follows:

Environment:
  apr-util : 1.3.9
  ubuntu   : 9.04
  mysql    : 5.0.75
  TABLE  Structure:
  CREATE TABLE `testTable` {
   `id` int(11) NOT NULL,
   `userName` varchar(100) NOT NULL,
   PRIMARY KEY (`id`)
  }ENGINE=MyISAM DEFAULT CHARSET=latin1;
     Source:
#include "apu.h"
#include "apr_pools.h"
#include "apr_dbd.h"

#include <stdio.h>

int main(int argc, char **argv) {
   const char *name = "mysql";
   const char *params =
           "host=127.0.0.1,user=root,pass=123456,dbname=testDB,port=3306";
   apr_pool_t *pool = NULL;
   apr_dbd_t *sql = NULL;
   const apr_dbd_driver_t *driver = NULL;
   int rv;

   const char *query = "SELECT  userName  FROM testTable where 
id=%d";/*this query exec info:ok!!!*/
   //const char *query = "SELECT * FROM testTable where id=%d";/*this 
query exec info:"Exec of prepared statement failed!"???*/
   const char *label = "getUserName";
   apr_dbd_prepared_t *statement = NULL;
   apr_dbd_results_t *res = NULL;
   apr_dbd_row_t *row = NULL;
   const char *entry = NULL;
   int i, n;

   apr_initialize();
   apr_pool_create(&pool, NULL);

   apr_dbd_init(pool);
   rv = apr_dbd_get_driver(pool, name, &driver);

   switch (rv) {
   case APR_SUCCESS:
       printf("Loaded %s driver OK.\n", name);
       break;
   case APR_EDSOOPEN:
       printf("Failed to load driver file apr_dbd_%s.so\n", name);
       goto finish;
   case APR_ESYMNOTFOUND:
       printf("Failed to load driver apr_dbd_%s_driver.\n", name);
       goto finish;
   case APR_ENOTIMPL:
       printf("No driver available for %s.\n", name);
       goto finish;
   default: /* it's a bug if none of the above happen */
       printf("Internal error loading %s.\n", name);
       goto finish;
   }

   rv = apr_dbd_open(driver, pool, params, &sql);
   switch (rv) {
   case APR_SUCCESS:
       printf("Opened %s[%s] OK\n", name, params);
       break;
   case APR_EGENERAL:
       printf("Failed to open %s[%s]\n", name, params);
       goto finish;
   default: /* it's a bug if none of the above happen */
       printf("Internal error opening %s[%s]\n", name, params);
       goto finish;
   }

   rv = apr_dbd_prepare(driver, pool, sql, query, label, &statement);
   if (rv) {
       printf("Prepare statement failed!\n%s\n",
               apr_dbd_error(driver, sql, rv));
       return rv;
   }

   int user_id = 1;
   rv
           = apr_dbd_pvselect(driver, pool, sql, &res, statement, 0, 
&user_id,
                   NULL);

   if (rv) {
       printf("Exec of prepared statement failed!\n%s\n", apr_dbd_error(
               driver, sql, rv));
       return rv;
   }

   i = 0;
   for (rv = apr_dbd_get_row(driver, pool, res, &row, -1); rv == 0; rv
           = apr_dbd_get_row(driver, pool, res, &row, -1)) {
       printf("ROW %d:    ", ++i);
       for (n = 0; n < apr_dbd_num_cols(driver, res); ++n) {
           entry = apr_dbd_get_entry(driver, row, n);
           if (entry == NULL) {
               printf("(null)    ");
           } else {
               printf("%s    ", entry);/*printf Nothing???*/
           }
       }
       fputs("\n", stdout);
   }

   finish:
       printf("finish");
       apr_pool_destroy(pool);
       apr_terminate();              
       return 0;
}


Bojan Smojver 写道:
> On Wed, 2010-01-27 at 13:40 +0800, liuxulin wrote:
>   
>> Is there anything wrong?
>>     
>
> Without going into details, compile the thing (your program and APU)
> with -g and -O0, then run it with gdb and step all the way through to
> see where the failure actually occurs. This will give you a better
> indication as to what actually went wrong.
>
> Also, increase verbosity of you MySQL log, in order to see what's going
> on on the server side.
>
>   


Mime
View raw message