List:MySQL++« Previous MessageNext Message »
From:Mensfort Date:September 26 2012 5:18am
Subject:Re: Problem using the sql_create_# macro in a header file
View as plain text  
Dear Layna,

You are putting code in the include file, which is compiled for each 
time it is included. This code should be moved to the cpp file or used 
inside the class. For example these 3 steps:

1) In the include file you put a class around your functions:

class CsqlCreator
{
         CsqlCreator() {}
         ~CsqlCreator() {}

         static void createMyDatabase()
         {

	sql_create_5(DBPTrans, 1, 5,

                mysqlpp::sql_int, trans_id,

                mysqlpp::sql_datetime, trans_time,

                mysqlpp::sql_varchar, trans_type,

                mysqlpp::sql_char, ticket_id,

                mysqlpp::sql_mediumtext, data);
    }
};

2) At the moment you create the database, use :
          CsqlCreator    x;
          x.createMyDatabase();

3) Also, you should put following line on top of each include file:
#pragma once



On 26-09-12 06:37, Layna Francisco wrote:
>
> -----Original Message-----
> From: Chris Morgan [mailto:christopher.j.morgan@stripped]
> Sent: Wednesday, 26 September, 2012 12:36 PM
> To: Kevin Smith
> Cc: plusplus@stripped
> Subject: Re: Problem using the sql_create_# macro in a header file
>
> Have you followed the steps in section 5.8 of the user manual (
> http://tangentsoft.net/mysql++/doc/html/userman/ssqls.html)? Specifically
> the use of MYSQLPP_SSQLS_NO_STATICS
>
> -Chris
>
> On Tue, Sep 25, 2012 at 9:14 PM, Kevin Smith <ksmith@stripped> wrote:
>
>> Hi,
>>
>>
>>
>>    I am writing an application where I have created an interface class
>> to the mysql database.  The class contains a vector of SSQLS objects
>> which are defined by the sql_create_# macro.  I have placed the macro
>> in the header file for the interface class so that the definition of
>> the SSQLS structure is available to the class vector definition.
>> Everything compiles nicely, but when the program is linked, if there
>> are multiple files that include the header, there are multiple
>> definitions of a couple of the functions that are created by the
>> macro.  If only one file includes the header, then there are no
>> problems.  Do you have a work around for this?
>>
>>
>>
>> MyHeader.h
>>
>>
>>
>> #include <mysql++.h>
>>
>> #include <ssqls.h>
>>
>> #include <vector>
>>
>>
>>
>>
>>
>>
>>
>> using namespace std;
>>
>>
>>
>> class dbInterface {
>>
>>
>>
>> public:
>>
>>                 dbInterface ();
>>
>>                 int pushTransaction (void);
>>
>>                 bool flush(void);
>>
>>
>>
>> private:
>>
>>                 bool dbupdateLastTransaction(void);
>>
>>                 bool dbWriteTransactionList(void);
>>
>> vector < DBPTrans > dbptransvect;
>>
>> };
>>
>>
>>
>>
>>
>> Support A.cpp
>>
>>
>>
>> #include "MyHeader.h"
>>
>>
>>
>> ..
>>
>>
>>
>>
>>
>> Main.cpp
>>
>>
>>
>> #include "MyHeader.h"
>>
>>
>>
>> ..
>>
>>
>>
>>
>>
>> When Linked, there will be functions in SupportA and Main that are
>> multiply defined, and it happens with sql_create made function.
>>
>>
>>
>> Thanks in advance!
>>
>>
>>
>> -Kevin
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>


Thread
Problem using the sql_create_# macro in a header fileKevin Smith26 Sep
  • Re: Problem using the sql_create_# macro in a header fileChris Morgan26 Sep
    • RE: Problem using the sql_create_# macro in a header fileLayna Francisco26 Sep
      • Re: Problem using the sql_create_# macro in a header fileMensfort26 Sep
        • Re: Problem using the sql_create_# macro in a header fileMickael Wolff26 Sep
    • RE: Problem using the sql_create_# macro in a header fileKevin Smith26 Sep