Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » SQL tutorial 5 and using namespace Upp; in header file (Solved)
SQL tutorial 5 and using namespace Upp; in header file (Solved) [message #52791] Mon, 25 November 2019 17:22 Go to next message
coolman is currently offline  coolman
Messages: 114
Registered: April 2006
Location: Czech Republic
Experienced Member
Hi,

It may be a stupid question, but I can't figure it out.

If you take a look at https://www.ultimatepp.org/srcdoc$Sql$tutorial$en-us.html#5 you can see "using namespace Upp;" in the MyApp.h.

How can I avoid this usage in header file and still be able to use defined SqlId constants in other source files (there can be more than one source file using the SqlID constants)?

BR, Radek

[Updated on: Sat, 30 November 2019 05:14]

Report message to a moderator

Re: SQL tutorial 5 and using namespace Upp; in header file (Solved) [message #52805 is a reply to message #52791] Sat, 30 November 2019 05:14 Go to previous messageGo to next message
coolman is currently offline  coolman
Messages: 114
Registered: April 2006
Location: Czech Republic
Experienced Member
Hi,

The solution is simple - in the header and source file enclose include and definitions related to SQL into block "namespace Upp". And move command "using namespace Upp;" from header file to source file.

MyApp.h
#ifndef _MyApp_h_
#define _MyApp_h_

#include <Core/Core.h>
#include <plugin/sqlite3/Sqlite3.h>

namespace Upp {
#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
#define MODEL <Sql05/MyApp.sch>
#include "Sql/sch_header.h"
}

#endif


main.cpp
#include "MyApp.h"

using namespace Upp;

namespace Upp {
#include <Sql/sch_schema.h>
#include <Sql/sch_source.h>
}

CONSOLE_APP_MAIN
{
....

[Updated on: Sat, 30 November 2019 05:14]

Report message to a moderator

Re: SQL tutorial 5 and using namespace Upp; in header file (Solved) [message #52806 is a reply to message #52805] Sat, 30 November 2019 12:12 Go to previous message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello coolman,

Nice catch! I think for the visibility reasons we should use following notation:

MyApp.h
#ifndef _MyApp_h_
#define _MyApp_h_

#include <Core/Core.h>
#include <plugin/sqlite3/Sqlite3.h>

namespace Upp
{
	#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
	#define MODEL <Sql05/MyApp.sch>
	#include "Sql/sch_header.h"
}

#endif


MyApp.cpp:
#include "MyApp.h"

namespace Upp
{
	#include <Sql/sch_schema.h>
	#include <Sql/sch_source.h>
}

using namespace Upp;

CONSOLE_APP_MAIN
{


Wit additional level of indent the construction is much more visible. In my opinion "using namespace Upp" should be used after include block to not interfere with includes.

Sincerely,
Klugier


U++ - one framework to rule them all.

[Updated on: Sat, 30 November 2019 12:12]

Report message to a moderator

Previous Topic: sql innerjoin not working
Next Topic: BUGFIX: MySqlConnection::SetParam(): handling INT64_V is missing
Goto Forum:
  


Current Time: Thu Mar 28 13:54:14 CET 2024

Total time taken to generate the page: 0.01030 seconds