Re: Com_empty_query

Eric Bergen <[email protected]>
Newsgroups gmane.comp.db.mysql.devel
Message-ID <CAL8wyNxwVqy4sCpOcZp3Yof2VYOcWfyPfcDbdjx6qKatrT+dfg@mail.gmail.com>
I think there are a few things going on. The first is that the command
line client is returning no query specified which means it didn't send
anything to the server. I wrote a small C app to send an empty query
to the server and it returns a "Query was empty" error then does a
show status on the same connection to check the counter. The counter
isn't incremented. I checked the source and the only increment I see
for empty_queries happens at the end of execute_sqlcom_select which
won't get called on an empty query. I think it needs to be incremented
in case SQLCOM_EMPTY_QUERY: in sql_parse.cc

Here is my small app for reference:

#include <stdio.h>
#include <string.h>
#include <mysql.h>

int main() {
    MYSQL con;
    MYSQL_RES *res;
    MYSQL_ROW row;
    char show_query[] = "show status like '%empty%'";
    int num_fields, i;
    mysql_init(&con);

    if (!(mysql_real_connect(&con, "", "root", "", "test", 3306,
"/home/ebergen/store/mysql/standalone_mariadb/mysql.sock", 0)))
    {
        printf("Connection failed with %s\n", mysql_error(&con));
        return 1;
    }

    if ((mysql_real_query(&con, "", 0)))
    {
        printf("Query failed with %s\n", mysql_error(&con));
        // return 1;
    }


    if (mysql_real_query(&con, show_query, strlen(show_query)))
    {
        printf("Show query failed with %s\n", mysql_error(&con));
        return 1;
    }

    res = mysql_store_result(&con);
    num_fields = mysql_num_fields(res);

    while ((row = mysql_fetch_row(res))) {
        for (i = 0; i < num_fields; i++)
        {
            printf("%s\n", (char *)row[i]);
        }
    }

    return 0;
}

On Thu, Oct 6, 2011 at 11:26 AM, Derek Downey <[email protected]> wrote:
> Hi,
>  I was trying to find out what would trigger the counter on Com_empty_query and my two test cases do not trigger it:
>
> mysql> SHOW STATUS LIKE 'Com_empty%';
> +-----------------+-------+
> | Variable_name   | Value |
> +-----------------+-------+
> | Com_empty_query | 0     |
> +-----------------+-------+
> 1 row in set (0.00 sec)
>
> mysql> SELECT * FROM foo WHERE bar=2;
> Empty set (0.03 sec)
>
> mysql> ;
> ERROR:
> No query specified
>
> mysql> SHOW STATUS LIKE 'Com_empty%';
> +-----------------+-------+
> | Variable_name   | Value |
> +-----------------+-------+
> | Com_empty_query | 0     |
> +-----------------+-------+
> 1 row in set (0.00 sec)
>
> Looking at the source, it seems to get triggered on an END_OF_INPUT in the query section of 'sql_yacc.yy' (assuming the query is syntactically correct). sql_lex.cc is the only instance that returns an END_OF_INPUT (after a lip->eof()), but I can't seem to trigger it.
>
> Is this triggered on a breakdown from the client, or on a certain type of (reproducible) query?
>
> Thanks,
>  Derek Downey
> --
> MySQL Internals Mailing List
> For list archives: http://lists.mysql.com/internals
> To unsubscribe:    http://lists.mysql.com/[email protected]
>
>



-- 
Eric Bergen
[email protected]
http://www.ebergen.net

-- 
MySQL Internals Mailing List
For list archives: http://lists.mysql.com/internals
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.