Error
Error
От:
<operationsengineer1@yahoo.com>
Дата:
i have the following code...
// start
$db = &ADONewConnection('postgres');
$db ->
Connect($db_string,$db_owner,$db_pw,$db_name);
// $db -> debug=true;
$customer_name =
$form->GetInputValue('customer_name');
$customer_id = $db->getone("select
nextval('t_customer_cust_id_seq')");
$sql_insert = <<<_EOSQL
INSERT INTO t_customer (customer_id,
customer_name, customer_entry_date)
VALUES (?,?,?)
_EOSQL;
$result = $db->Execute($sql_insert,
array($customer_id, $customer_name,
$db->DBDate(time())));
//end code
it produces the following error...
ERROR: column "customer_id" is of type integer but
expression is of type boolean HINT: You will need to
rewrite or cast the expression.
any ideas?
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
Re: Error
От:
<operationsengineer1@yahoo.com>
Дата:
--- Charley Tiggs wrote:
> On Nov 30, 2005, at 3:35 PM,
>
> wrote:
>
> > i have the following code...
> >
> > // start
> >
> > $db = &ADONewConnection('postgres');
> > $db ->
> > Connect($db_string,$db_owner,$db_pw,$db_name);
> > // $db -> debug=true;
> >
> > $customer_name =
> > $form->GetInputValue('customer_name');
> > $customer_id = $db->getone("select
> > nextval('t_customer_cust_id_seq')");
> >
> > $sql_insert = <<<_EOSQL
> >
> > INSERT INTO t_customer (customer_id,
> > customer_name, customer_entry_date)
> > VALUES (?,?,?)
> >
> > _EOSQL;
> >
> > $result = $db->Execute($sql_insert,
> > array($customer_id, $customer_name,
> > $db->DBDate(time())));
> >
> > //end code
> >
> > it produces the following error...
> >
> > ERROR: column "customer_id" is of type integer but
> > expression is of type boolean HINT: You will need
> to
> > rewrite or cast the expression.
> >
> > any ideas?
>
> What's the value of $customer_id before you attempt
> the insert?
>
> right after $customer_id variable is set, do the
> following:
>
> echo $customer_id . '
';
> echo gettype ( $customer_id );
> exit;
>
the answer is... boolean.
> With ADO, a couple of times, I've run into a glitch
> where bindings
> changed types. Haven't taken the time to figure out
> why. Switching
> to autoExecute solves the problem:
>
> $insert_array = array ( 'customer_id' =>
> $db->getone("select nextval
> ('t_customer_cust_id_seq')"),
> 'customer_name' =>
> $form->GetInputValue('customer_name'),
> 'customer_entry_date' => $db->DBDate(time()))
>
> $result = $db->autoExecute ( 't_customer',
> $insert_array,
> 'INSERT' );
>
> Most likely, the reason it works for me is that I
> cleaned up my error
> when switching to the autoExecute method.
>
> Charley
Charley, i'm not sure. this code worked before i
upgraded both pgsql. at least i'm pretty darn sure it
did. then again, maybe i've lost my mind. having
said that, i don't see anything in the code that says
"boolean" to me.
i will try and cast it is an integer and let the adodb
maintainer know about this issue.
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
Re: Error
От:
<operationsengineer1@yahoo.com>
Дата:
> What's the value of $customer_id before you attempt > the insert? > > right after $customer_id variable is set, do the > following: > > echo $customer_id . '
'; > echo gettype ( $customer_id ); > exit; > > With ADO, a couple of times, I've run into a glitch > where bindings > changed types. Haven't taken the time to figure out > why. Switching > to autoExecute solves the problem: > > $insert_array = array ( 'customer_id' => > $db->getone("select nextval > ('t_customer_cust_id_seq')"), > 'customer_name' => > $form->GetInputValue('customer_name'), > 'customer_entry_date' => $db->DBDate(time())) > > $result = $db->autoExecute ( 't_customer', > $insert_array, > 'INSERT' ); > > Most likely, the reason it works for me is that I > cleaned up my error > when switching to the autoExecute method. > > Charley using php to cast to to an integer... $customer_id = (int) $customer_id; ...worked for me. i have a note in on the adodb forum to find out why it is casting as boolean. __________________________________ Yahoo! Music Unlimited Access over 1 million songs. Try it free. http://music.yahoo.com/unlimited/
Re: Error
От:
Charley Tiggs <ctiggs@xpressdocs.com>
Дата:
On Nov 30, 2005, at 3:35 PM,
wrote:
> i have the following code...
>
> // start
>
> $db = &ADONewConnection('postgres');
> $db ->
> Connect($db_string,$db_owner,$db_pw,$db_name);
> // $db -> debug=true;
>
> $customer_name =
> $form->GetInputValue('customer_name');
> $customer_id = $db->getone("select
> nextval('t_customer_cust_id_seq')");
>
> $sql_insert = <<<_EOSQL
>
> INSERT INTO t_customer (customer_id,
> customer_name, customer_entry_date)
> VALUES (?,?,?)
>
> _EOSQL;
>
> $result = $db->Execute($sql_insert,
> array($customer_id, $customer_name,
> $db->DBDate(time())));
>
> //end code
>
> it produces the following error...
>
> ERROR: column "customer_id" is of type integer but
> expression is of type boolean HINT: You will need to
> rewrite or cast the expression.
>
> any ideas?
What's the value of $customer_id before you attempt the insert?
right after $customer_id variable is set, do the following:
echo $customer_id . '
';
echo gettype ( $customer_id );
exit;
With ADO, a couple of times, I've run into a glitch where bindings
changed types. Haven't taken the time to figure out why. Switching
to autoExecute solves the problem:
$insert_array = array ( 'customer_id' => $db->getone("select nextval
('t_customer_cust_id_seq')"),
'customer_name' => $form->GetInputValue('customer_name'),
'customer_entry_date' => $db->DBDate(time()))
$result = $db->autoExecute ( 't_customer',
$insert_array,
'INSERT' );
Most likely, the reason it works for me is that I cleaned up my error
when switching to the autoExecute method.
Charley
Re: Error
От:
Charley Tiggs <ctiggs@xpressdocs.com>
Дата:
On Nov 30, 2005, at 7:12 PM, wrote: >> What's the value of $customer_id before you attempt >> the insert? >> >> right after $customer_id variable is set, do the >> following: >> >> echo $customer_id . '
'; >> echo gettype ( $customer_id ); >> exit; >> >> With ADO, a couple of times, I've run into a glitch >> where bindings >> changed types. Haven't taken the time to figure out >> why. Switching >> to autoExecute solves the problem: >> >> $insert_array = array ( 'customer_id' => >> $db->getone("select nextval >> ('t_customer_cust_id_seq')"), >> 'customer_name' => >> $form->GetInputValue('customer_name'), >> 'customer_entry_date' => $db->DBDate(time())) >> >> $result = $db->autoExecute ( 't_customer', >> $insert_array, >> 'INSERT' ); >> >> Most likely, the reason it works for me is that I >> cleaned up my error >> when switching to the autoExecute method. >> >> Charley > > using php to cast to to an integer... > > $customer_id = (int) $customer_id; > > ...worked for me. i have a note in on the adodb forum > to find out why it is casting as boolean. I think your query failed. After you execute this query: >> $customer_id = $db->getone("select nextval >> ('t_customer_cust_id_seq')"); do the following: echo $db->ErrorMsg(); exit; That will tell you why the query failed. Charley
Re: Error
От:
<operationsengineer1@yahoo.com>
Дата:
--- Charley Tiggs wrote: > On Nov 30, 2005, at 7:12 PM, > > wrote: > > >> What's the value of $customer_id before you > attempt > >> the insert? > >> > >> right after $customer_id variable is set, do the > >> following: > >> > >> echo $customer_id . '
'; > >> echo gettype ( $customer_id ); > >> exit; > >> > >> With ADO, a couple of times, I've run into a > glitch > >> where bindings > >> changed types. Haven't taken the time to figure > out > >> why. Switching > >> to autoExecute solves the problem: > >> > >> $insert_array = array ( 'customer_id' => > >> $db->getone("select nextval > >> ('t_customer_cust_id_seq')"), > >> 'customer_name' => > >> $form->GetInputValue('customer_name'), > >> 'customer_entry_date' => > $db->DBDate(time())) > >> > >> $result = $db->autoExecute ( 't_customer', > >> $insert_array, > >> 'INSERT' ); > >> > >> Most likely, the reason it works for me is that I > >> cleaned up my error > >> when switching to the autoExecute method. > >> > >> Charley > > > > using php to cast to to an integer... > > > > $customer_id = (int) $customer_id; > > > > ...worked for me. i have a note in on the adodb > forum > > to find out why it is casting as boolean. > > I think your query failed. great call. > After you execute this query: > > >> $customer_id = $db->getone("select nextval > >> ('t_customer_cust_id_seq')"); > > do the following: > > echo $db->ErrorMsg(); > exit; > > That will tell you why the query failed. > > Charley it says... ERROR: relation "t_customer_cust_id_seq" does not exist i'm off to hunt down the actual name of the sequence. bottom line - if you get a boolean response, check to see if the query has failed first. thank you for the insight. __________________________________ Yahoo! Music Unlimited Access over 1 million songs. Try it free. http://music.yahoo.com/unlimited/
Re: Error
От:
Marcus Engene <mengpg@engene.se>
Дата:
> it says...
>
> ERROR: relation "t_customer_cust_id_seq" does not
> exist
>
> i'm off to hunt down the actual name of the sequence.
>
> bottom line - if you get a boolean response, check to
> see if the query has failed first.
>
> thank you for the insight.
Quite a few functions in php do this. If you use the
syntax == or != it is C-style compare. That is, zero
is false and basically the rest is true.
If you use === or !== it evaluates to true if both
the types are equal AND the statement is true.
So, the correct syntax would be
if (false === ($customer_id = $db->getone("..."))) {
error handling.
}
Example from the manual:
// in PHP 4.0b3 and newer:
$pos = strrpos($mystring, "b");
if ($pos === false) { // note: three equal signs
// not found...
}
By doing this, strrpos can return 0 (not an error) or
false (not found). Without === strrpos would have to
return -1 or some other illegal position for not found.
Best regards,
Marcus