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 » Developing U++ » U++ TheIDE and Library: Releases and ChangeLogs » Schema utilities
Schema utilities [message #17549] Wed, 20 August 2008 12:14 Go to next message
mirek is currently offline  mirek
Messages: 11844
Registered: November 2005
Ultimate Member
I recently have to deal with existing database (not created from .sch file).

To make things easier, I have added these utility functions to Sql:

String ExportSch(SqlSession& session, const String& database);
String ExportSch(const String& database);

- exports the database to .sch format

String ExportIds(SqlSession& session, const String& database);
String ExportIds(const String& database);

- exports table and column names as SQLID (or new SQL_ID(id, sqlid) to deal with case sensitivity in mysql).

Mirek
Re: Schema utilities [message #20627 is a reply to message #17549] Fri, 27 March 2009 21:42 Go to previous messageGo to next message
rtmex is currently offline  rtmex
Messages: 9
Registered: March 2009
Location: Puebla, MEXICO
Promising Member
Hello

I'm new to Ultimate++

I have a PostgreSQL database, how can I connect to a database to create the .sch file?

I think this post of you is for doing something like that, but I don't know how to use this ExportSch function you say.

Could you put a source code example please?

Thanks in advance
Re: Schema utilities [message #20632 is a reply to message #20627] Sat, 28 March 2009 08:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11844
Registered: November 2005
Ultimate Member
http://www.ultimatepp.org/reference$SQL_PostgreSql.html
Re: Schema utilities [message #20668 is a reply to message #20632] Mon, 30 March 2009 22:14 Go to previous messageGo to next message
rtmex is currently offline  rtmex
Messages: 9
Registered: March 2009
Location: Puebla, MEXICO
Promising Member
Hi

I know that example, but that example asummes that you already have the .sch file, and that's exactly what I want to generate by connecting to the database.
Besides, I don't see ExportSch ExportIds in that example

Smile

Maybe I did not explain myself well the first time

I want to know how to generate the .sch file connecting to a database that already exist.
I think thats what the ExportSch function does, I would appreciate if you can put an example of how this can be done.

Thanks in advance
Re: Schema utilities [message #20674 is a reply to message #20668] Tue, 31 March 2009 13:03 Go to previous messageGo to next message
andrei_natanael is currently offline  andrei_natanael
Messages: 262
Registered: January 2009
Experienced Member
I think it's pretty simple. Ignore .sch files which already exist in that example. In OpenDB() comment everything which is after //schema line (only return true should stay there). Somewhere in your program use
SaveFile("filename", ExportSch(m_session, "test"));
// or
SaveFile("filename", ExportSch("test"));
// you may also assign content returned by ExportSch to a Upp control

Second version use global SQL session.
Re: Schema utilities [message #20697 is a reply to message #20674] Tue, 31 March 2009 22:24 Go to previous messageGo to next message
rtmex is currently offline  rtmex
Messages: 9
Registered: March 2009
Location: Puebla, MEXICO
Promising Member
Hello

I try what you said, this is my cpp file

#include "creabase.h"

#include <Sql/sch_schema.h>
#include <Sql/sch_source.h>

using namespace Upp;

creabase::creabase()
{
CtrlLayout(*this, "Window title");
}

bool creabase::OpenDB()
{
if(!m_session.Open("host=localhost dbname=test user=postgres password=prueba"))
{
Exclamation(Format("Error in open: %s", DeQtf(m_session.GetLastError())));
return false;
}


#ifdef _DEBUG
m_session.SetTrace();
#endif

SaveFile("estructura.sch", Exportsch(m_session, "test"));
return true;
}


GUI_APP_MAIN
{
creabase dlg;

if(dlg.OpenDB())
{
dlg.Run();
}
}

I'm getting the next error

error: 'Exportsch' was not declared in this scope

I think I have to add an include file but I don't know wich one, I added the Sql and PostgreSQL packages to my program.
I had to put an empty database.sch file because if I didn't, I got an error saying the file does not exist.

I'm also getting this messages when I compile the program

CtrlLib: circular 'uses' chain
CtrlLib: circular 'uses' chain

This is my .h file

#ifndef _creabase_creabase_h
#define _creabase_creabase_h

#include <CtrlLib/CtrlLib.h>
#include <SqlCtrl/SqlCtrl.h>

using namespace Upp;

#define LAYOUTFILE <creabase/creabase.lay>
#include <CtrlCore/lay.h>

#include <PostgreSQL/PostgreSQL.h>
#define SCHEMADIALECT <PostgreSQL/PostgreSQLSchema.h>
#define MODEL <creabase/database.sch>
#include "Sql/sch_header.h"

class creabase : public WithcreabaseLayout<TopWindow> {
public:
typedef creabase CLASSNAME;
creabase();
bool OpenDB();

protected:
PostgreSQLSession m_session;
};

#endif
Re: Schema utilities [message #20699 is a reply to message #20697] Wed, 01 April 2009 04:13 Go to previous message
andrei_natanael is currently offline  andrei_natanael
Messages: 262
Registered: January 2009
Experienced Member
rtmex wrote


SaveFile("estructura.sch", Exportsch(m_session, "test"));
...
I'm getting the next error

error: 'Exportsch' was not declared in this scope


It's name is wrong, it should be ExportSch not Exportsch

rtmex wrote


I think I have to add an include file but I don't know wich one, I added the Sql and PostgreSQL packages to my program.
I had to put an empty database.sch file because if I didn't, I got an error saying the file does not exist.

I'm also getting this messages when I compile the program

CtrlLib: circular 'uses' chain
CtrlLib: circular 'uses' chain


The only required header is SqlSchema.h.
The warnings(or errors) about "circular 'uses' chain"(i've never had such an error) , i think are because you're using "using namespace Upp" twice - once in header and once in .cpp file.

I don't have a PostgreSQL database but i've modified SQLApp example to test ExportSch. The only modifications i've made are in main.cpp.

// line 5
void SchExport()
{
	SaveFile("estructura.sch", ExportSch(SQL.GetSession(), ""));
}

void SQLApp::MainMenu(Bar& bar)
{
	bar.Add("ExportSch", callback(SchExport));
    // ...
}


If you don't get it i may make a small example, but i think it's obvious.


P.S.: use code tags(formating tools) to make your code more readable in posts.
Previous Topic: readonly nests
Next Topic: TheIDE: Package highlight experiment
Goto Forum:
  


Current Time: Fri Apr 26 06:48:42 CEST 2019

Total time taken to generate the page: 0.00827 seconds