mysql_real_query causing segmentation fault for binary select

2009-12-04 Thread Michael Pawlowsky

I am trying top run these 2 SELECT queries using mysql_real_query in MySQL-C.

The only difference between them is changing the first hex value from 41 to 01.

It if is 41, the query runs fine. When I change it to 01 I get the following 
segmentation fault.

segfault at 0 ip 00402be6 sp 7fff01e5bee0 error 4 in 
apnsd[40+7000]


SELECT `id` FROM `apns`.`tblTokens` WHERE `token_id` = 
0x01A161E6CEAC902311B2357792F6076A3CEA85FA9B0B071A77289FC450D7092E LIMIT 1
SELECT `id` FROM `apns`.`tblTokens` WHERE `token_id` = 
0x41A161E6CEAC902311B2357792F6076A3CEA85FA9B0B071A77289FC450D7092E LIMIT 1


token_id is defines as:  binary(32)
I also tried it a char(32) with the same results


Any insight on why this is happening?




  /* Connect to database */
   if (!mysql_real_connect(conn, db_host,
 db_user, db_password, db_name, 0, NULL, 0)) {

 /* log an error */
syslog(LOG_ERR,"Unable to connect to DB. Error: %s", 
mysql_error(conn));
mysql_close(conn);

/* Can't connect to DB... Bailing out */
return(ERROR);
   }

   if (mysql_real_query(conn, "SELECT `id` FROM `apns`.`tblTokens` WHERE 
`token_id` = 0x01A161E6CEAC902311B2357792F6076A3CEA85FA9B0B071A77289FC450D7092E 
LIMIT 1", 129)) {
 /* log an error */
syslog(LOG_ERR,"Failed to SELECT, Error: %s", 
mysql_error(conn));
syslog(LOG_ERR, "Query: %s", query);
mysql_close(conn);

/* Failed to select from DB... Bailing out */
return(ERROR);
   } 

return(0);








--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



How to create a relationship to another row in the same table

2009-10-03 Thread Michael Pawlowsky


I'm having a hard time trying to find the best way to create a  
relationship between two rows in the same table.


I have a database that describes network equipment.

There is a table called devices that contains information about the  
device.


There is another table called ports that describe different types of  
ports (electric, ethernet, serial) and so on. It has a foreign key to  
the device.


What I need now is a way to connect two ports together. So for  
instance, if it was an ethernet port the connection would be from  
perhaps a server to a switch.


I could have a table (connections) with 2 rows in it for each entry  
(from server port to switch port and another one from the switch port  
back to server port) but this seems redundant.
If I create a cross reference table with a primary key on (port_id_a,  
port_id_b) it still allows me to recreate the same connection but in  
the reverse order. This should not be allowed since we can only  
connect ports 1 to 1.


I'vr thought about keeping the connected port relationship in the  
ports table and updating two rows every time a change is made. But  
once again, I'm thinking this should be down using only 1 row.


Any of any ideas on an elegant database structure to do this?


Thanks in advance for your input,
Mike




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Select ENUM values

2004-08-24 Thread Michael Pawlowsky
I'm wondering if there is a better way to select the
values of a ENUM field. I have a ENUM field called
greeting that has 'Mr.','Mrs.','Ms.','Dr.' in it. I
need to put these in a HTML select.

Right now I'm doing a "SHOW COLUMNS FROM global_lead
LIKE 'greeting'" and then parsing out the response for
the enum values (found on mysql site).

But I was thinking there might be a more elegant way
to do it.

Is there?

Thanks,
Mike


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]