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 |
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 |
|
mirek
Messages: 14038 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 |
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 #22414 is a reply to message #22413] |
Sun, 12 July 2009 15:43 |
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
|
|
|
Goto Forum:
Current Time: Fri Sep 20 04:44:55 CEST 2024
Total time taken to generate the page: 0.03363 seconds
|