Query issues - works manually... doesn"t with mysql_real_query
Query issues - works manually... doesn"t with mysql_real_query
am 29.08.2006 15:21:39 von elitecodex
Hey everyone. I have this query
select * from `TableName` where `SomeIDField` > 0
I can open a mysql command prompt and execute this command with no
issues. However, Im trying to issue the same command inside of
mysql_real_query and I keep on getting this error back.
"You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '' at line 1"
I added \n's to my string to determine that its not liking the end of
my query. So here is the quick snippet of code.
stl::string query ="select * from `TableName` where `SomeIDField` > 0";
// .... some other non-important stuff ...
if ( mysql_real_query(&m_Mysql, query.c_str(), query.length()+2) != 0 )
{
status->Error(mysql_errno(&m_Mysql), "Query failed! [" +
stl::string(mysql_error(&m_Mysql)) + "]");
}
So thats it. What am I missing?
Also, a side question. The above line only works with the third
parameter being query.length() + 2. +1 Gives me a seg fault. Why is
this? Isn't the null character a single character??
Thanks for all help in advance!
Re: Query issues - works manually... doesn"t with mysql_real_query
am 29.08.2006 17:45:52 von shakah
Why the "+2"? Supplying the actual length seems to work just fine,
e.g.:
std::string query ="select * from `TableName` where `SomeIDField` > 0";
if ( mysql_real_query(&m_Mysql, query.c_str(), query.length()) != 0 )
elitecodex wrote:
> Hey everyone. I have this query
>
> select * from `TableName` where `SomeIDField` > 0
>
> I can open a mysql command prompt and execute this command with no
> issues. However, Im trying to issue the same command inside of
> mysql_real_query and I keep on getting this error back.
>
> "You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use
> near '' at line 1"
>
> I added \n's to my string to determine that its not liking the end of
> my query. So here is the quick snippet of code.
>
> stl::string query ="select * from `TableName` where `SomeIDField` > 0";
> // .... some other non-important stuff ...
> if ( mysql_real_query(&m_Mysql, query.c_str(), query.length()+2) != 0 )
> {
> status->Error(mysql_errno(&m_Mysql), "Query failed! [" +
> stl::string(mysql_error(&m_Mysql)) + "]");
> }
>
> So thats it. What am I missing?
>
> Also, a side question. The above line only works with the third
> parameter being query.length() + 2. +1 Gives me a seg fault. Why is
> this? Isn't the null character a single character??
>
> Thanks for all help in advance!
Re: Query issues - works manually... doesn"t with mysql_real_query
am 31.08.2006 12:37:45 von elitecodex
shakahshakah@gmail.com wrote:
> Why the "+2"? Supplying the actual length seems to work just fine,
> e.g.:
>
> std::string query ="select * from `TableName` where `SomeIDField` > 0";
> if ( mysql_real_query(&m_Mysql, query.c_str(), query.length()) != 0 )
>
>
>
> elitecodex wrote:
> > Hey everyone. I have this query
> >
> > select * from `TableName` where `SomeIDField` > 0
> >
> > I can open a mysql command prompt and execute this command with no
> > issues. However, Im trying to issue the same command inside of
> > mysql_real_query and I keep on getting this error back.
> >
> > "You have an error in your SQL syntax; check the manual that
> > corresponds to your MySQL server version for the right syntax to use
> > near '' at line 1"
> >
> > I added \n's to my string to determine that its not liking the end of
> > my query. So here is the quick snippet of code.
> >
> > stl::string query ="select * from `TableName` where `SomeIDField` > 0";
> > // .... some other non-important stuff ...
> > if ( mysql_real_query(&m_Mysql, query.c_str(), query.length()+2) != 0 )
> > {
> > status->Error(mysql_errno(&m_Mysql), "Query failed! [" +
> > stl::string(mysql_error(&m_Mysql)) + "]");
> > }
> >
> > So thats it. What am I missing?
> >
> > Also, a side question. The above line only works with the third
> > parameter being query.length() + 2. +1 Gives me a seg fault. Why is
> > this? Isn't the null character a single character??
> >
> > Thanks for all help in advance!
I cannot answer that in total honesty... But query.length() and
query.length() + 1 both resulted in segfaults. +2 is the only way I
could get it to run.... well, at least not crash. mysql_real_query did
not like just the length.
Re: Query issues - works manually... doesn"t with mysql_real_query
am 31.08.2006 13:26:01 von elitecodex
elitecodex wrote:
> shakahshakah@gmail.com wrote:
> > Why the "+2"? Supplying the actual length seems to work just fine,
> > e.g.:
> >
> > std::string query ="select * from `TableName` where `SomeIDField` > 0";
> > if ( mysql_real_query(&m_Mysql, query.c_str(), query.length()) != 0 )
> >
> >
> >
> > elitecodex wrote:
> > > Hey everyone. I have this query
> > >
> > > select * from `TableName` where `SomeIDField` > 0
> > >
> > > I can open a mysql command prompt and execute this command with no
> > > issues. However, Im trying to issue the same command inside of
> > > mysql_real_query and I keep on getting this error back.
> > >
> > > "You have an error in your SQL syntax; check the manual that
> > > corresponds to your MySQL server version for the right syntax to use
> > > near '' at line 1"
> > >
> > > I added \n's to my string to determine that its not liking the end of
> > > my query. So here is the quick snippet of code.
> > >
> > > stl::string query ="select * from `TableName` where `SomeIDField` > 0";
> > > // .... some other non-important stuff ...
> > > if ( mysql_real_query(&m_Mysql, query.c_str(), query.length()+2) != 0 )
> > > {
> > > status->Error(mysql_errno(&m_Mysql), "Query failed! [" +
> > > stl::string(mysql_error(&m_Mysql)) + "]");
> > > }
> > >
> > > So thats it. What am I missing?
> > >
> > > Also, a side question. The above line only works with the third
> > > parameter being query.length() + 2. +1 Gives me a seg fault. Why is
> > > this? Isn't the null character a single character??
> > >
> > > Thanks for all help in advance!
>
> I cannot answer that in total honesty... But query.length() and
> query.length() + 1 both resulted in segfaults. +2 is the only way I
> could get it to run.... well, at least not crash. mysql_real_query did
> not like just the length.
Ok, I figured since the way I am suppose to do this is just use
query.length() I decided to change it back to that and figure out the
segfault.
Here is the gdb output.
#0 0xb7d3cd31 in free_root () from /usr/lib/libmysqlclient.so.15
#1 0xb7d677cc in free_old_query () from /usr/lib/libmysqlclient.so.15
#2 0xb7d6c54f in mysql_close () from /usr/lib/libmysqlclient.so.15
#3 0xb7d6cc04 in mysql_real_query () from
/usr/lib/libmysqlclient.so.15
#4 0xb7ea8fdc in will::db::DbMysqlProtocol::QueryEx (this=0x8053108,
query=
{static npos = 4294967295, _M_dataplus =
{> = {<__gnu_cxx::new_allocator> = {
fields>}, }, _M_p = 0x8054ef4 "select * from
TableName"}}, resultPointer=0x8053d08, numRows=0x8054478) at
db_mysql_protocol.cpp:118
Why would mysql_real_query() call mysql_close() ?? I cannot find the
implementation in the Mysql source code that has anything to do with
mysql_close. Can someone point me in the correct direction here?
Thanks alot!
Re: Query issues - works manually... doesn"t with mysql_real_query
am 31.08.2006 13:59:32 von shakah
elitecodex wrote:
> elitecodex wrote:
> > shakahshakah@gmail.com wrote:
> > > Why the "+2"? Supplying the actual length seems to work just fine,
> > > e.g.:
> > >
> > > std::string query ="select * from `TableName` where `SomeIDField` > 0";
> > > if ( mysql_real_query(&m_Mysql, query.c_str(), query.length()) != 0 )
> > >
> > >
> > >
> > > elitecodex wrote:
> > > > Hey everyone. I have this query
> > > >
> > > > select * from `TableName` where `SomeIDField` > 0
> > > >
> > > > I can open a mysql command prompt and execute this command with no
> > > > issues. However, Im trying to issue the same command inside of
> > > > mysql_real_query and I keep on getting this error back.
> > > >
> > > > "You have an error in your SQL syntax; check the manual that
> > > > corresponds to your MySQL server version for the right syntax to use
> > > > near '' at line 1"
> > > >
> > > > I added \n's to my string to determine that its not liking the end of
> > > > my query. So here is the quick snippet of code.
> > > >
> > > > stl::string query ="select * from `TableName` where `SomeIDField` > 0";
> > > > // .... some other non-important stuff ...
> > > > if ( mysql_real_query(&m_Mysql, query.c_str(), query.length()+2) != 0 )
> > > > {
> > > > status->Error(mysql_errno(&m_Mysql), "Query failed! [" +
> > > > stl::string(mysql_error(&m_Mysql)) + "]");
> > > > }
> > > >
> > > > So thats it. What am I missing?
> > > >
> > > > Also, a side question. The above line only works with the third
> > > > parameter being query.length() + 2. +1 Gives me a seg fault. Why is
> > > > this? Isn't the null character a single character??
> > > >
> > > > Thanks for all help in advance!
> >
> > I cannot answer that in total honesty... But query.length() and
> > query.length() + 1 both resulted in segfaults. +2 is the only way I
> > could get it to run.... well, at least not crash. mysql_real_query did
> > not like just the length.
>
> Ok, I figured since the way I am suppose to do this is just use
> query.length() I decided to change it back to that and figure out the
> segfault.
>
> Here is the gdb output.
>
> #0 0xb7d3cd31 in free_root () from /usr/lib/libmysqlclient.so.15
> #1 0xb7d677cc in free_old_query () from /usr/lib/libmysqlclient.so.15
> #2 0xb7d6c54f in mysql_close () from /usr/lib/libmysqlclient.so.15
> #3 0xb7d6cc04 in mysql_real_query () from
> /usr/lib/libmysqlclient.so.15
> #4 0xb7ea8fdc in will::db::DbMysqlProtocol::QueryEx (this=0x8053108,
> query=
> {static npos = 4294967295, _M_dataplus =
> {> = {<__gnu_cxx::new_allocator> = {
> fields>}, }, _M_p = 0x8054ef4 "select * from
> TableName"}}, resultPointer=0x8053d08, numRows=0x8054478) at
> db_mysql_protocol.cpp:118
>
> Why would mysql_real_query() call mysql_close() ?? I cannot find the
> implementation in the Mysql source code that has anything to do with
> mysql_close. Can someone point me in the correct direction here?
> Thanks alot!
It's hard to tell without seeing your code, but are you checking the
return codes from the calls to mysql_init() and mysql_real_connect()
prior to your call to mysql_real_query()? Also, have you tried just
hard-coding a simple query like "SELECT 'x'" or "SELECT 1"? Tried using
mysql_query() instead of mysql_real_query?
Re: Query issues - works manually... doesn"t with mysql_real_query
am 05.09.2006 13:06:30 von elitecodex
shakahshakah@gmail.com wrote:
> elitecodex wrote:
> > elitecodex wrote:
> > > shakahshakah@gmail.com wrote:
> > > > Why the "+2"? Supplying the actual length seems to work just fine,
> > > > e.g.:
> > > >
> > > > std::string query ="select * from `TableName` where `SomeIDField` > 0";
> > > > if ( mysql_real_query(&m_Mysql, query.c_str(), query.length()) != 0 )
> > > >
> > > >
> > > >
> > > > elitecodex wrote:
> > > > > Hey everyone. I have this query
> > > > >
> > > > > select * from `TableName` where `SomeIDField` > 0
> > > > >
> > > > > I can open a mysql command prompt and execute this command with no
> > > > > issues. However, Im trying to issue the same command inside of
> > > > > mysql_real_query and I keep on getting this error back.
> > > > >
> > > > > "You have an error in your SQL syntax; check the manual that
> > > > > corresponds to your MySQL server version for the right syntax to use
> > > > > near '' at line 1"
> > > > >
> > > > > I added \n's to my string to determine that its not liking the end of
> > > > > my query. So here is the quick snippet of code.
> > > > >
> > > > > stl::string query ="select * from `TableName` where `SomeIDField` > 0";
> > > > > // .... some other non-important stuff ...
> > > > > if ( mysql_real_query(&m_Mysql, query.c_str(), query.length()+2) != 0 )
> > > > > {
> > > > > status->Error(mysql_errno(&m_Mysql), "Query failed! [" +
> > > > > stl::string(mysql_error(&m_Mysql)) + "]");
> > > > > }
> > > > >
> > > > > So thats it. What am I missing?
> > > > >
> > > > > Also, a side question. The above line only works with the third
> > > > > parameter being query.length() + 2. +1 Gives me a seg fault. Why is
> > > > > this? Isn't the null character a single character??
> > > > >
> > > > > Thanks for all help in advance!
> > >
> > > I cannot answer that in total honesty... But query.length() and
> > > query.length() + 1 both resulted in segfaults. +2 is the only way I
> > > could get it to run.... well, at least not crash. mysql_real_query did
> > > not like just the length.
> >
> > Ok, I figured since the way I am suppose to do this is just use
> > query.length() I decided to change it back to that and figure out the
> > segfault.
> >
> > Here is the gdb output.
> >
> > #0 0xb7d3cd31 in free_root () from /usr/lib/libmysqlclient.so.15
> > #1 0xb7d677cc in free_old_query () from /usr/lib/libmysqlclient.so.15
> > #2 0xb7d6c54f in mysql_close () from /usr/lib/libmysqlclient.so.15
> > #3 0xb7d6cc04 in mysql_real_query () from
> > /usr/lib/libmysqlclient.so.15
> > #4 0xb7ea8fdc in will::db::DbMysqlProtocol::QueryEx (this=0x8053108,
> > query=
> > {static npos = 4294967295, _M_dataplus =
> > {> = {<__gnu_cxx::new_allocator> = {
> > fields>}, }, _M_p = 0x8054ef4 "select * from
> > TableName"}}, resultPointer=0x8053d08, numRows=0x8054478) at
> > db_mysql_protocol.cpp:118
> >
> > Why would mysql_real_query() call mysql_close() ?? I cannot find the
> > implementation in the Mysql source code that has anything to do with
> > mysql_close. Can someone point me in the correct direction here?
> > Thanks alot!
>
> It's hard to tell without seeing your code, but are you checking the
> return codes from the calls to mysql_init() and mysql_real_connect()
> prior to your call to mysql_real_query()? Also, have you tried just
> hard-coding a simple query like "SELECT 'x'" or "SELECT 1"? Tried using
> mysql_query() instead of mysql_real_query?
Ok... my stupidity. Sometimes I wish I could find these things prior
to posting online. My issue that I thought that mysql_library_init was
a replacement for mysql_init... so I never called mysql_init. Before I
was doing this
mysql_library_init()
mysql_real_connect()
// queries
mysql_library_end()
So I changed it to this and it worked
mysql_library_init()
mysql_init()
mysql_real_connect()
// queries
mysql_library_end()
mysql_close()
just a bit of confusion on my part from the Mysql docs. Perhaps my
stupidity will help someone else :) Thanks alot for your help
shakahshakah.