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 » ExportSch, zero byte file is the result
ExportSch, zero byte file is the result [message #21927] Thu, 11 June 2009 04:15 Go to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
I'm unable to make this work. I connect to the database just fine, query the database just fine, but when I do this:

SaveFile("mydb.sch", ExportSch(SQL.GetSession(), "mydb"));


I wind up with mydb.sch that is 0 bytes.

Jeremy
Re: ExportSch, zero byte file is the result [message #21932 is a reply to message #21927] Thu, 11 June 2009 19:10 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, I have recently (2 weeks ago) used this code to study the schema of existing database:

#include <MySql/MySql.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	MySqlSession session;
	// substitute your 'username' and 'password' here:
	if(!session.Connect("root", "heslo", "test", "10.0.0.19")) {
		printf("Can't connect with MySql\n");
		return;
	}
	Sql sql(session);
	sql.Execute("use test");
	sql.Execute("show tables");
	while(sql.Fetch())
		Cout() << (String)sql[0] << '\n';
	SaveFile("u:/lego.sch", ExportSch(session, "test"));
	SaveFile("u:/legoid", ExportIds(session, "test"));
}


and it seems to have worked well....

Mirek
Re: ExportSch, zero byte file is the result [message #21961 is a reply to message #21932] Fri, 12 June 2009 14:30 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
Ok, I found the problem, it's specific to PostgreSQL. The query that gets run to enum the tables is:

select n.nspname || '.' || c.relname 
from pg_catalog.pg_class c 
    left join pg_catalog.pg_namespace n on n.oid = c.relnamespace 
where c.relkind = 'r' and 
    n.nspname like 'mydb' and 
    pg_catalog.pg_table_is_visible(c.oid)


When I call:

ExportSch(session, "mydb");


There is no namespace named "mydb". It's named "public". Here's an example output:

mydb=> SELECT n.nspname,n.oid FROM pg_catalog.pg_namespace n;
      nspname       |   oid
--------------------+----------
 pg_catalog         |       11
 pg_toast           |       99
 pg_temp_1          |    11052
 pg_toast_temp_1    |    11053
 information_schema |    11313
 public             |     2200
 pg_temp_34         | 23600075
 pg_toast_temp_34   | 23600076
(8 rows)


Only the tables that are in the current database are accessible. So, anything public is really what's in the connected database. If I change my code to read:

ExportSch(session, "public");


even though I am connected to "mydb", then the schema is dumped.

I ran your code that you posted above (with a PostgreSQLSession instead) and it writes a 0 byte file. Doing what is above in this message causes everything to work.

Jeremy
Re: ExportSch, zero byte file is the result [message #21962 is a reply to message #21961] Fri, 12 June 2009 14:32 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
Oh, I forgot to say that the schema gets exported as:

TABLE_(public.roles)
	STRING  (name, 20)
	STRING  (description)
END_TABLE


i.e. everything has public.

Jeremy
Re: ExportSch, zero byte file is the result [message #22407 is a reply to message #21927] Fri, 10 July 2009 19:30 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
Any thoughts on having to give the database name for MySQL but having to give "public" for PostgreSQL? also the fact that it writes the table names such as public.table_name not just table_name ?

Jeremy
Re: ExportSch, zero byte file is the result [message #22413 is a reply to message #22407] Sun, 12 July 2009 09:32 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
jeremy_c wrote on Fri, 10 July 2009 13:30

Any thoughts on having to give the database name for MySQL but having to give "public" for PostgreSQL? also the fact that it writes the table names such as public.table_name not just table_name ?

Jeremy



If you post a path, I will include it.

Anyway, this is really simple utility function used for very special reasons. I am content with it as it works now.

In fact, originally I have written it only for my one time own purposes, only including it because it does not really affect anything else and might be useful for others.

(Maybe I should have uploaded it to bazaar?)

Mirek
Re: ExportSch, zero byte file is the result [message #22414 is a reply to message #22413] Sun, 12 July 2009 15:43 Go to previous message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
luzr wrote on Sun, 12 July 2009 03:32


If you post a path, I will include it.

Anyway, this is really simple utility function used for very special reasons. I am content with it as it works now.

In fact, originally I have written it only for my one time own purposes, only including it because it does not really affect anything else and might be useful for others.



Ok. I'll work up a patch.

luzr wrote on Sun, 12 July 2009 03:32


(Maybe I should have uploaded it to bazaar?)



I think you did right. It will be of help to many, many people. I don't think it will be hard to make it work properly on different databases.

Jeremy
Previous Topic: umlauts in mysql-update
Next Topic: Needs Moved - Errors when compiling - Allocation Functions not Linking? [VS2008]
Goto Forum:
  


Current Time: Fri Mar 29 11:18:41 CET 2024

Total time taken to generate the page: 0.03366 seconds