in reply to Re: Type casting
in thread Type casting

Hey, Thanks but it isnt working....can look at my code..
use Win32::ODBC; my @rows; my $make1="Acura"; $year=int($year); # $year+=0; $year=1992; my $DSN = "carcov"; if (!($db = new Win32::ODBC($DSN))){ print "error connecting to $DSN\n"; print "error: " . Win32::ODBC::Error() . "\n"; exit; } die qq(SQL failed: ), $db->Error(), qq(\n) if ($db->Sql("SE +LECT DISTINCT modelname,startyear,endyear FROM model +,detail,make WHERE detail.modelid=model.mod +elid AND detail.makeid=make.makeid AND make.makename='$make1' AND startyear <= '$year' AND endyear >= '$year'"));

Replies are listed 'Best First'.
Re: Re: Re: Type casting
by cLive ;-) (Prior) on Jul 18, 2001 at 03:41 UTC

    First, print you SQL statement to check it looks OK.

    Then try it with less requirements to see whether you're asking for an impossible dataset.

    Then ummm... I'll get back to you...

    clive ;-)

Re: Re: Re: Type casting
by chipmunk (Parson) on Jul 18, 2001 at 06:29 UTC
    Although you want $year to be treated by the database as a number, you've put single quotes around it in the SQL, which tells the database the value is a string.

    Try removing the single quotes around $year in the SQL, and maybe even using placeholders instead, if MS Access supports them.

Re: Re: Re: Type casting
by HyperZonk (Friar) on Jul 18, 2001 at 04:08 UTC
    Well, there are some notes above that may make this irrelevant, but you are doing the assignement after the $year+=0;. When trying to force evaluation as a number, you should do the +=0 trick after, not before the assignment.
Re: Re: Re: Type casting
by rchiav (Deacon) on Jul 18, 2001 at 03:51 UTC
    From this, it looks like your SQL string contains carrige returns. I don't belive you can do that.

    If that's not the case, what happens if you just replace all occurances of $year with a hard coded int?

    Rich

    Update: Thanks to crazyinsomniac for correcting me. SQL is not delimited by a CR so I was completely off base.

Re: Re: Re: Type casting
by synapse0 (Pilgrim) on Jul 18, 2001 at 03:53 UTC
    Type really shouldn't make a difference here, since, when it's passed to the db, it's all a string anyway. But to make sure, you can always just drop $year and add 1992 in the code and see what the return is. I'm betting it will be the same result, in which case you will have to look elsewhere for the flaw.
    -Syn0

    update: damn, rchiav beat me :) .. another thing, when forcing the type, you dont' want to do it before you declare what's in $year, you want to do it during or after.
    for example: $year = 1992; $year = int($year); or $year = 1992+0;