[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql-plusplus
Subject:    Re: How to use NULL values in mysql++?
From:       "Greg Haley \(aka gregor\) " <ghaley () mail ! venaca ! com>
Date:       2001-07-11 16:43:18
[Download RAW message or body]

	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)
> >

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic