[Gambas-user] can a result database object be copy to other database (of different type)

Tobias Boege taboege at ...626...
Mon May 22 19:48:16 CEST 2017


On Mon, 22 May 2017, PICCORO McKAY Lenz wrote:
> umm usefully, but the source its odbc.. was my faul...
> 
> in any case, there's posible to cpy between results object of differents
> connections? that the right quiestion!
> 

Ok, after I formulated my answer, I can see how you may want to use Gambas
for this task.

Assume you have hSrc and hDst two Connections -- hSrc is the source database
and hDst is the destination database. The DB types don't matter! I would do
the conversion in two stages:

  1. Copy the database users (Connection.Users), then the databases
     (Connection.Databases) and after that the table schemas (Connection.Tables)
     for each database. I don't think you can expect to transfer anything
     else like permissions because it is not supported by the gb.db
     interface (sqlite doesn't even support users).

     You can use the gb.db objects for this, e.g. to copy the schema of a
     database table, you get the corresponding Table object and iterate
     through its Fields member to get all the fields. Luckily the field
     types are db.String, db.Integer, etc., i.e. *Gambas* constants. You
     can easily transfer this common representation of the table schema to
     your destination database.

  2. Copy all the records. hSrc.Find(tablename) (or so) gives you all the
     records in the given table. Recreate all the records in the appropriate
     destination database table, using hDst.Create(tablename).

I'm reasonably sure that there is no less manual way. But beware that you
might run into problems of all thinkable kinds, e.g. with auto-increment
fields which you may or may not be allowed to set on your own when you
create a record, or maybe one database type stores milliseconds together
with a date while the other is incapable of that. What do I know?

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list