From: Raymond Boettcher Date: April 3 2011 11:33am Subject: Re: Mysql++ AVOID NULL Columns!! :) List-Archive: http://lists.mysql.com/plusplus/9306 Message-Id: <109510.83468.qm@web38003.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1065788053-1301830436=:83468" --0-1065788053-1301830436=:83468 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hello PlusPlus Mailing List!, Actually, I'm kinda new to using mailing lists, so I replied to all only be= cause I wasn't certain if the reply should go back to plusplus@stripped.= com or to the specific user.=A0 I hope this doesn't get me spammed...=A0 An= yhow, moving on... I've had this problem and I've been using MySQL++ for quite some time.=A0 I= think at this point in development there are members mysqlpp::null and is_= null functions that can be used to test for it.=A0 When I started using Mys= ql++ this wasn't true and often lead to program crashes, etc. I think??=A0 Don't quote me, should work: if(string(vbasketballevent[b]["tf_station_num"]) !=3D mysqlpp::null ) I have found that comparing using components of mysqlpp against DB informat= ion tends to give better results.=A0 I even use mysqlpp::sql_int_unsigned, = etc for some of my variables only because trying to compare the information= with C++'s int has also given me bad compile issues in the past.=A0 I'm no= t sure if this is still true... However, I recommend you do exactly as I've done since I started using this= library and go into MySQL Administrator, edit the table and check the "Not= Null" field and clear and default to a zero charactor string or 0 (integer= s, etc) for the default value if it doesn't do it automatically when you ap= ply the "Not Null" settings to the table.=A0 This will ensure that strings = are set to "" integers are set to 0, dates are set to 0000-00-00 00:00:00, = etc.=A0 Unless you have some strange reason that you need a field to be set= to null.=A0 I just take Null out of the equation altogether.=A0 In everyth= ing that I've ever written that uses mysql++, I've never found one instance= to use null with. I did lookup a syntax for making the modification yourself but it has to be= done with every column you want to never be set to Null... ALTER TABLE `Database`.`Table` MODIFY COLUMN `ColumnName` VARCHAR(45) NOT N= ULL; Of course VARCHAR being the field type and maybe able to be omitted and jus= t specify "NOT NULL" since the entry already exists and omitting it should = leave the field type the same.=A0 If you creating the column for the first = time just remember to tack "NOT NULL" to the end of it. I generally create all my tables for the first time using MySQL Administrat= or, so its become habit to ensure that check mark is checked off.=A0 If my = program happens to crash on such an instance, usually a quick check of the = tables leads me back to the "Not Null" issue. I hope this helps.=A0 I rarely get a chance to comment on a list like this,= but this is one of the few things that made me pull my hair out one day, s= o I feel your pain... -RayRay- --- On Sat, 4/2/11, Jonathan Wakely wrote: From: Jonathan Wakely Subject: Re: Actually it was this one. To: "Eric Sepich" Cc: plusplus@stripped Date: Saturday, April 2, 2011, 5:32 PM On 2 April 2011 22:02, Eric Sepich wrote: > cout << string(vbasketballevent[b]["tf_station_num"]) << endl; > > Sorry about that. I have to take my last email back. Most of the time > everything is fine but once in a while there seems to be some problem > with vbasketballevent[b]["tf_station_num"]. > I think perhaps it might be NULL. How would I check and prepare an if > statement? Could I use > > if(string(vbasketballevent[b]["tf_station_num"]) !=3D NULL) =A0????? > > I've been struggling to get a debugger set up on Linux for months now. I > can't seem to find one that operates as well as Microsoft Visual C++ Expr= ess > so I have been debugging on Windows and running the program on Linux. Run the program in gdb, when it segfaults type "where" to see where it cras= hed. There are some GUID front ends to GDB listed at http://sourceware.org/gdb/wiki/GDB%20Front%20Ends but it's easiest just to use GDB.=A0 There's not setting up necessary. --0-1065788053-1301830436=:83468--