dbTalk Databases Forums  

help... how do i use SSQLS within my own classes...

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss help... how do i use SSQLS within my own classes... in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
joh3@lithophile.com
 
Posts: n/a

Default help... how do i use SSQLS within my own classes... - 12-19-2006 , 10:20 PM






Hi,
I am hoping that some of you with greater mysql++ and c++ experience can help
me. What I want is to be able to use the SSQLS generated code as part of a
larger object....

FYI... I can get all the example code to work fine, and i am happy using the
rest of the mysql++ libs but this SSQLS area still has me stuck... anyway any
help would be appreciated.

so my pseudo header code would look something like this...

<<<<file PSmh.h>>>>>

sql_create_8(Target_Region, 1, 0,
mysqlpp::sql_int, Target_ID,
string, Target_name,
string, root_path,
string, file_path,
mysqlpp::sql_int, Master_id,
string, Target_region_geom,
string, Combined_Amplitude_image_path,
mysqlpp::sql_int, resume_state)


class PSmh
{/* {{{ */
// some public methods
private:
vector<Target_Region> My_target;
}/* }}} */

however.... using this style gives me lots of compile errors.....

g++ -o psinsar logger.cxx Jerr.cxx config-handler.cxx mysql_psinsar_harmony.cxx
psinsar.cxx -I. -I/usr/include/boost -I/usr/include/stlsoft
-I/usr/include/mysql -g -ggdb -Wall `mysql_config --cflags` -fexceptions
`gsl-config --cflags` `gsl-config --libs` `mysql_config --libs` -L/usr/lib/ -l
mysqlpp -L/lib -L/usr/lib -lz -lm -lboost_program_options -L.

/tmp/ccc67q0l.o:/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/exception:55:
multiple definition of `Target_Region::names'

/tmp/ccsfwwq0.o:/usr/include/mysql++/lockable.h:139: first defined here

/tmp/ccc67q0l.o:/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/iostream:78:
multiple definition of `Target_Region::_table'

/tmp/ccsfwwq0.o:/usr/include/mysql++/noexceptions.h:60: first defined here

collect2: ld returned 1 exit status

make: *** [psinsar] Error 1

can someone give me some hints how i can get this working?


also i need to extend the mysql++ library to use the geospatial mysql
extensions, i am slowly working out how mysql++ all fits together, would you
like patches to make them work if i can get it working? if so how do i submit
them? should they be against the svn code or the base mysql++ 2.1.1 code?

thanks in advance for all your help, and merry christmas

Cheers

Joe


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Joel Fielder
 
Posts: n/a

Default RE: help... how do i use SSQLS within my own classes... - 12-20-2006 , 02:47 AM






Hi,

The SSQLS macros declare and define static variables for the structure,
including the table name, Target_Region::_table. The compiler is
whining because you can only define a static variable once (because
there is only one instance of it).

There is a #define called MYSQLPP_SSQLS_NO_STATICS which you can use to
tell the SSQLS macros to just declare the static variables.

So #define MYSQLPP_SSQLS_NO_STATICS somewhere, and then assign values to
the statics just once i.e. in your .cpp file. The easiest way to do
this is to repeat the sql_create call in your .cpp file but with
MYSQLPP_SSQLS_NO_STATICS undefined. I wouldn't recommend this though as
the preprocessor will then do double the work.

Instead, you can just directly assign values in the .cpp file as you
would normally when dealing with static variables.

Target_Region::_table = "target_region";
Target_Region::names[] = { "Target_ID", "Target_name", "root_path",
"etc" };


Regarding patches for extending the library, I can't comment on the need
or otherwise for this, but I can refer you to the HACKERS document
within the mysql++ distribution which recommends patching against the
SVN version.

Joel.


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #3  
Old   
Warren Young
 
Posts: n/a

Default Re: help... how do i use SSQLS within my own classes... - 12-20-2006 , 12:21 PM



joh3 (AT) lithophile (DOT) com wrote:
Quote:
/tmp/ccc67q0l.o:/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/iostream:78:
multiple definition of `Target_Region::_table'
Every SSQLS type includes two static member variables; _table is one.
If you don't do anything to avoid it, they're assigned default values
within the sql_create_* macro, so if the compiler sees that macro call
twice, it sees two separate assignments to a static member variable,
which annoys it.

To fix this, I would put the sql_create_* macro in a separate .h file,
and #define MYSQLPP_SSQLS_NO_STATICS above all #includes for that file
except for one. This ensures that the static members are assigned to
only once. You can see this pattern in action in the examples: the
'stock' SSQLS type is defined in stock.h, and it is included in both
util.cpp and in custom*.cpp.

Your situation is slightly more complex because you are #including the
SSQLS definition within a .h file. You'll probably need a little C
preprocessor work to avoid problems here.

Quote:
also i need to extend the mysql++ library to use the geospatial mysql
extensions, i am slowly working out how mysql++ all fits together, would you
like patches to make them work if i can get it working?
Simple patches like this usually get accepted pretty quickly. I suggest
looking at lib/sql_types.h.

Quote:
should they be against the svn code or the base mysql++ 2.1.1 code?
Against svn, if at all possible. That makes it easier for you to
generate diffs, and for me to apply them.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #4  
Old   
joh3@lithophile.com
 
Posts: n/a

Default Re: help... how do i use SSQLS within my own classes... - 12-20-2006 , 01:25 PM



Thanks for your help in this, i really appreciate it...

i am going to have to research the preprocessor work, so that i can get it all
together....

cheers

Joe

Warren Young wrote:
Quote:
joh3 (AT) lithophile (DOT) com wrote:

/tmp/ccc67q0l.o:/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/iostream:78:

multiple definition of `Target_Region::_table'

Every SSQLS type includes two static member variables; _table is one. If
you don't do anything to avoid it, they're assigned default values
within the sql_create_* macro, so if the compiler sees that macro call
twice, it sees two separate assignments to a static member variable,
which annoys it.

To fix this, I would put the sql_create_* macro in a separate .h file,
and #define MYSQLPP_SSQLS_NO_STATICS above all #includes for that file
except for one. This ensures that the static members are assigned to
only once. You can see this pattern in action in the examples: the
'stock' SSQLS type is defined in stock.h, and it is included in both
util.cpp and in custom*.cpp.

Your situation is slightly more complex because you are #including the
SSQLS definition within a .h file. You'll probably need a little C
preprocessor work to avoid problems here.

also i need to extend the mysql++ library to use the geospatial mysql
extensions, i am slowly working out how mysql++ all fits together,
would you
like patches to make them work if i can get it working?

Simple patches like this usually get accepted pretty quickly. I suggest
looking at lib/sql_types.h.

should they be against the svn code or the base mysql++ 2.1.1 code?

Against svn, if at all possible. That makes it easier for you to
generate diffs, and for me to apply them.



--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #5  
Old   
Warren Young
 
Posts: n/a

Default Re: help... how do i use SSQLS within my own classes... - 12-20-2006 , 02:21 PM



joh3 (AT) lithophile (DOT) com wrote:
Quote:
i am going to have to research the preprocessor work, so that i can get it all
together....
It's just an ifdef guard. #if included from the .cpp file, do it this
way, #else do it this other way.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.