4 messages in com.mysql.lists.plusplusRe: How to use NULL values in mysql++?| From | Sent On | Attachments |
|---|---|---|
| Pavel Matula | 11 Jul 2001 06:23 | |
| Trem | 11 Jul 2001 08:35 | |
| Pavel Matula | 11 Jul 2001 09:09 | |
| Greg Haley (aka gregor) | 11 Jul 2001 09:42 |
| Subject: | Re: How to use NULL values in mysql++?![]() |
|---|---|
| From: | Greg Haley (aka gregor) (gha...@mail.venaca.com) |
| Date: | 07/11/2001 09:42:56 AM |
| List: | com.mysql.lists.plusplus |
Hi, if you have a lot of records where you will not be able to predict whether there are null values, you might write something that dynamically builds your sql string with a set of if loops or maybe even a switch:
pseudo code might look like:
if (item_value) {
insert_string .= "item, ";
value_string .= " item_value, ";
}
if (num_value) {
insert_string .= "num, ";
value_string .= " num_value, ";
}
sql_string = "INSERT into stock (" << value_string << ") VALUES (" <<
value_string << ")"";
since your table is not prohibiting nulls, when you do the insert, the missing columns will default to NULL.
one thing is to test for stray commas, which will make your submit blow up.
ciao! greg.
Gregory Haley DBA/Web Programmer Venaca, LLC.
Hello,
Is anywhere a tutorial of working with NULL values in mysql++? Where is problem of NULL values in mysql++ described?
If I use custom1.cc example for table mysql> create table stock (item varchar(255), num int, weight decimal(5,2), price decimal(5,2), sdate date);
having values mysql> insert into stock values ("aaa", 1, 12.3, NULL, '12-3-2001'); mysql> insert into stock values ("bbb", 2, NULL, NULL, '4-5-2001');
it returns following message
Error: Tried to convert "NULL" to a "d"
What should be data type for columns in sql_create_5 (stock, // struct name, 1, 5, // I'll explain these latter string, item, // type, id longlong, num, double, weight, double, price, Date, sdate)




