1 message in com.mysql.lists.plusplusSimple question on setting NULL value...| From | Sent On | Attachments |
|---|---|---|
| Eric Vaandering | 21 Feb 2001 11:47 |
| Subject: | Simple question on setting NULL values in column![]() |
|---|---|
| From: | Eric Vaandering (ew...@fnal.gov) |
| Date: | 02/21/2001 11:47:40 AM |
| List: | com.mysql.lists.plusplus |
Hi,
I'm very much a newbie at this, so please understand if my question is
simplistic.
I'm trying to put a NULL value into a couple of field to get auto-incrementing to work and a timestamp to work. Nothing I've done works, which means I'm not doing the right thing, I suppose.
Here's my code:
sql_create_7(TensionMeasurement,1,7,int,TensionID,double,Tension,double,Frequency, string,MeasuredBy,int,Date,int,Method, int,TubeID);
void MysqlTest () { try { MysqlConnection mysqlCon(use_exceptions); mysqlCon.connect(DATABASE,DBSERVER,DBTENSEUSER,DBTENSEPASS);
MysqlQuery testQuery = mysqlCon.query();
TensionMeasurement row; row.TensionID = 0; row.Tension = 5; row.Frequency = 500; row.MeasuredBy = "vondo"; row.Date = 0; row.Method = 2; row.TubeID = 42; testQuery.insert(row);
cout << "Query: " << testQuery.preview() << endl;
testQuery.execute(); } catch (BadQuery er) { cerr << "Bad Query \n"; } catch (BadConversion er) { cerr << "Error: Tried to convert \"" << er.data << "\" to a \"" << er.type_name << "\"." << endl; }
};
The tables are defined as follows:
mysql> show columns from TensionMeasurement \g +------------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+---------------+------+-----+---------+----------------+ | TensionID | int(11) | | PRI | NULL | auto_increment | | Tension | double | YES | | NULL | | | Frequency | double | YES | | NULL | | | MeasuredBy | char(32) | YES | | NULL | | | Date | timestamp(14) | YES | | NULL | | | Method | int(11) | YES | | NULL | | | TubeID | int(11) | | | 0 | | +------------+---------------+------+-----+---------+----------------+ 7 rows in set (0.00 sec)
Passing "0" to TensionID gets the autoincrement to work, but passing 0 to Date does not. I have to pass null to get the automatic time stamping to work. That's what I can't figure out.
Any help would be appreciated. If you could cc: me, that would be great since my subscription doesn't seem to have gone through yet.
Thanks,
Eric Vaandering
-- Eric Vaandering Phone: 615-343-6605 FAX: 615-343-7217 Vanderbilt University Email: ew...@fnal.gov Department of Physics http://www-hep.colorado.edu/~ewv/Home.html
______________________________________________________________________________ When you are young, you run out of gas to get lucky. At my age, when you get lucky, you run out of gas. -Phil Davis
______________________________________________________________________________ Inside every small problem is a large problem struggling to get out.




