Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Binary?

macphersonmacpherson Member Posts: 302
I am new to SQL of any kind and have just started using MySQL.

It appears there is no way of directly storing an integer to a table which has a column of type INT. It seems to me it has to be converted to a string of some kind first. Where am I going wrong? I have the book entitled "Managing & Using MySQL" by Reese et al. and it offers little direct help. Perhaps you can help clear the fog.

Comments

  • JonathanJonathan Member Posts: 2,914
    : I am new to SQL of any kind and have just started using MySQL.
    :
    : It appears there is no way of directly storing an integer to a table which has a column of type INT. It seems to me it has to be converted to a string of some kind first. Where am I going wrong? I have the book entitled "Managing & Using MySQL" by Reese et al. and it offers little direct help. Perhaps you can help clear the fog.
    :

    To interact with MySQL you have to send it SQL queries, which, as you appear to have discovered, are strings. So yes, you will need to do that. Iternally, column type INT results in the number being stored on disk as a number (not a string).

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • macphersonmacpherson Member Posts: 302
    : : I am new to SQL of any kind and have just started using MySQL.
    : :
    : : It appears there is no way of directly storing an integer to a table which has a column of type INT. It seems to me it has to be converted to a string of some kind first. Where am I going wrong? I have the book entitled "Managing & Using MySQL" by Reese et al. and it offers little direct help. Perhaps you can help clear the fog.
    : :
    :
    : To interact with MySQL you have to send it SQL queries, which, as you appear to have discovered, are strings. So yes, you will need to do that. Iternally, column type INT results in the number being stored on disk as a number (not a string).
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :
    [green]Is there a prize for decyphering the above?[/green]

    Thanks for the reply.

    So that means that the savings of having a 4 byte int are only in the database itself. So are ALL communications by strings which are then converted in MySQL to the appropriate form for storage?

    I understand having compact storage and having ASCII strings for universality but it seems a shame to go from a 4 byte int in my C code to a string then back to a 4 byte footprint on the disk and back again on a query.

  • JonathanJonathan Member Posts: 2,914
    : : ###
    : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : :
    : :
    : [green]Is there a prize for decyphering the above?[/green]
    No decyphering required, just run it. :-)

    : Thanks for the reply.
    You're welcome.

    : So that means that the savings of having a 4 byte int are only in
    : the database itself. So are ALL communications by strings which are
    : then converted in MySQL to the appropriate form for storage?
    Well, if you are sending an SQL query to the server (I guess you use sprintf in C to construct the SQL and put the number you wish to insert into the query?), then yes, that's a string...

    : I understand having compact storage and having ASCII strings for
    : universality but it seems a shame to go from a 4 byte int in my C
    : code to a string then back to a 4 byte footprint on the disk and
    : back again on a query.
    In a SELECT query I'm not honestly sure how the results are returned - I'm not at all familiar with the C MySQL API. It could be that ints really are returned as ints as the *result* of a SELECT query. If you are putting the data into an SQL query, then yes that is a string and conversion is needed. Result returns are something else I don't know about. Sorry...it'll be in some docs somewhere though.

    Types aren't something I often worry about when it comes to SQL stuff. In Perl, we don't have value types (e.g. string, int, num, etc)! Perl6 will, but it's optional. Anyway, you're a C guy so I won't blast you with Perl stuff. :-)

    Hope this has helped,

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.