apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevac Marko <ma...@kevac.org>
Subject Re: [PATCH] fix for max_length field to be populated for prepared statements
Date Fri, 02 Oct 2009 06:51:59 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=47932

On Thu, Oct 1, 2009 at 2:20 PM, Kevac Marko <marko@kevac.org> wrote:
> Without this attribute set, max_length field is not filled for
> prepared statements.
>
> This is from http://dev.mysql.com/doc/refman/5.0/en/c-api-datatypes.html :
>
> If you are using prepared statements, max_length is not set by default
> because for the binary protocol the lengths of the values depend on
> the types of the values in the result set. (See Section 20.9.5, “C API
> Prepared Statement Data types”.) If you want the max_length values
> anyway, enable the STMT_ATTR_UPDATE_MAX_LENGTH option with
> mysql_stmt_attr_set() and the lengths will be set when you call
> mysql_stmt_store_result(). (See Section 20.9.7.3,
> “mysql_stmt_attr_set()”, and Section 20.9.7.27,
> “mysql_stmt_store_result()”.)
>
> diff --git a/dbd/apr_dbd_mysql.c b/dbd/apr_dbd_mysql.c
> index 01afed2..0d206ac 100644
> --- a/dbd/apr_dbd_mysql.c
> +++ b/dbd/apr_dbd_mysql.c
> @@ -581,8 +581,14 @@ static int dbd_mysql_prepare(apr_pool_t *pool,
> apr_dbd_t *sql,
>     (*statement)->stmt = mysql_stmt_init(sql->conn);
>
>     if ((*statement)->stmt) {
> +        my_bool update_max_length = 1;
> +
>         apr_pool_cleanup_register(pool, (*statement)->stmt,
>                                   stmt_close, apr_pool_cleanup_null);
> +
> +        mysql_stmt_attr_set((*statement)->stmt, STMT_ATTR_UPDATE_MAX_LENGTH,
> +                            &update_max_length);
> +
>         ret = mysql_stmt_prepare((*statement)->stmt, query, strlen(query));
>
>         if (ret != 0) {
>
>
> --
> Marko Kevac
> Sent from Moscow, Mow, Russia
>



-- 
Marko Kevac
Sent from Moscow, Mow, Russia

Mime
View raw message