Professional Web Applications Themes

Syntax validation - MySQL

Hello, I want to know if there is any way of check if one sql statement is syntactic valid? If exists any function in mysql or in any other language that validates the syntax of a sql statement. Thanks, Nuno...

  1. #1

    Default Syntax validation

    Hello,

    I want to know if there is any way of check if one sql statement is
    syntactic valid? If exists any function in mysql or in any other
    language that validates the syntax of a sql statement.

    Thanks,
    Nuno

    Nuno Guest

  2. #2

    Default Re: Syntax validation

    On 13 Feb, 09:42, "Nuno" <com> wrote: 

    If you try to run it, it will tell you if the syntax is incorrect.
    Works pretty well for me!

    Captain Guest

  3. #3

    Default Re: Syntax validation

    On 13 Feb, 09:48, "Captain Paralytic" <com> wrote: 


    >
    > If you try to run it, it will tell you if the syntax is incorrect.
    > Works pretty well for me![/ref]

    Actually, entering it as a prepared statement may well syntax check it
    without running it.

    Captain Guest

  4. #4

    Default Re: Syntax validation

    Yes ok this is true, but i need to build some unit tests (in c++ cpp
    unit - automaticly tests) and the only thing that i want is to check
    if the result string (sql statement) given by a specific function from
    a specific class is valid or not.


    Captain Paralytic escreveu: 
    >
    > If you try to run it, it will tell you if the syntax is incorrect.
    > Works pretty well for me![/ref]

    Nuno Guest

  5. #5

    Default Re: Syntax validation

    What do you mean with "prepared statement", how this is done? is
    possible to do it with the mysql c++ library? if yes what is the
    function to do it?


    Captain Paralytic escreveu: 
    > > 
    > > 
    > >
    > > If you try to run it, it will tell you if the syntax is incorrect.
    > > Works pretty well for me![/ref]
    >
    > Actually, entering it as a prepared statement may well syntax check it
    > without running it.[/ref]

    Nuno Guest

  6. #6

    Default Re: Syntax validation

    On 13 Feb, 09:59, "Nuno" <com> wrote: [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]

    >
    > What do you mean with "prepared statement", how this is done? is
    > possible to do it with the mysql c++ library? if yes what is the
    > function to do it? 
    >
    > - Show quoted text -[/ref]

    Please do not top post!
    I tend to use mysql from php where there is a specifically to prepare
    statements.

    For answers to questions such as this one, might I respectfully
    suggest that you take a look at the manual!

    Captain Guest

  7. #7

    Default Re: Syntax validation

    Ok but you help me with your posts, and for this i thank you.

    The solution is calling the mysql_stmt_prepare function and it works
    fine.

    example:
    bool Valid(string str_sql)
    {
    MYSQL_STMT *stmt;
    stmt = mysql_stmt_init(mysql);
    if (!stmt)
    {
    printf(stderr, " mysql_stmt_init(), out of memory\n");
    return false;
    }
    if (mysql_stmt_prepare(stmt, INSERT_SAMPLE, strlen(INSERT_SAMPLE)))
    {
    printf(stderr, " mysql_stmt_prepare(), INSERT failed\n");
    printf(stderr, " %s\n", mysql_stmt_error(stmt));
    return false;
    }
    return true;
    }

    Thanks very much.

    Captain Paralytic escreveu: 
    > > 
    > > 
    > > 
    > > 
    > > 
    > >
    > > What do you mean with "prepared statement", how this is done? is
    > > possible to do it with the mysql c++ library? if yes what is the
    > > function to do it? 
    > >
    > > - Show quoted text -[/ref]
    >
    > Please do not top post!
    > I tend to use mysql from php where there is a specifically to prepare
    > statements.
    >
    > For answers to questions such as this one, might I respectfully
    > suggest that you take a look at the manual![/ref]

    Nuno Guest

  8. #8

    Default Re: Syntax validation

    :P

    bug on the example:
    bool Valid(string str_sql)
    {
    MYSQL_STMT *stmt;
    stmt = mysql_stmt_init(mysql);
    if (!stmt)
    {
    printf(stderr, " mysql_stmt_init(), out of memory\n");
    return false;
    }
    if ( mysql_stmt_prepare(stmt, str_sql, str_sql.length() ) )
    {
    printf(stderr, " mysql_stmt_prepare(), failed\n");
    printf(stderr, " %s\n", mysql_stmt_error(stmt));
    return false;
    }
    return true;
    }

    Now it's correct...

    Nuno escreveu: 
    > >
    > > Please do not top post!
    > > I tend to use mysql from php where there is a specifically to prepare
    > > statements.
    > >
    > > For answers to questions such as this one, might I respectfully
    > > suggest that you take a look at the manual![/ref][/ref]

    Nuno Guest

  9. #9

    Default Re: Syntax validation

    On 13 Feb, 11:45, "Nuno" <com> wrote: [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]


    >
    > - Show quoted text -[/ref]

    Glad to be of service

    Captain Guest

  10. #10

    Default Re: Syntax validation

    "Nuno" <com> wrote:
     

    you can use the MySQL Query Browser. it's a pretty good tool that'll
    tell you where your problem is.
    --
    -lark

    lark Guest

  11. #11

    Default Re: Syntax validation

    On 13 Feb, 14:55, lark <com> wrote: 


    >
    > you can use the MySQL Query Browser. it's a pretty good tool that'll
    > tell you where your problem is.
    > --
    > -lark[/ref]

    Yes, but not programatically as the OP needed to do.

    Captain Guest

  12. #12

    Default Re: Syntax validation

    Nuno wrote:
     


    Stick EXPLAIN in front of it and execute it - see what comes back.


    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
    Brian Guest

  13. #13

    Default Re: Syntax validation

    On 13 Feb, 21:00, Brian Wakem <com> wrote: 


    >
    > Stick EXPLAIN in front of it and execute it - see what comes back.
    >
    > --
    > Brian Wakem
    > Email:http://homepage.ntlworld.com/b.wakem/myemail.png[/ref]

    But EXPLAIN runs the query I believe

    Captain Guest

Similar Threads

  1. No syntax control during webservice validation in Visual Studio 8
    By worm@matfyz.cz in forum ASP.NET Web Services
    Replies: 3
    Last Post: March 20th, 09:56 AM
  2. CFFORM Validation trumping Custom Form Validation
    By Beals in forum Macromedia ColdFusion
    Replies: 17
    Last Post: July 19th, 06:40 PM
  3. Syntax for dynamic validation control
    By Chris Kennedy in forum ASP.NET Building Controls
    Replies: 1
    Last Post: June 8th, 09:16 PM
  4. Replies: 0
    Last Post: June 25th, 03:05 PM
  5. only custom validation control does server side validation?
    By Colin Mackay in forum ASP.NET General
    Replies: 0
    Last Post: June 25th, 07:54 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139