I want to create a copy database in file format from the one I'm already connected to.
After creating it, I want to immediately do stuff with it (populate it, run queries etc).
Is this possible?
example.p:
/* Copy currently connected 'mydb' database into new .db file with same schema but without any database rows */
RUN copyCurrentDatabaseToNewFileBasedDatabase.p("mydb", "C:\mydatabase\mydatabase.db").
/* Disconnect from current 'mydb' database */
DISCONNECT mydb.
/* Connect to copied and empty 'mydatabase.db' database */
CONNECT VALUE("-db C:\mydatabase\mydatabase.db -H localhost -S 20000").
/* Populate the copied database with some data */
RUN populateCopyDatabase.p.
/* Perform queries on the copied and populated database */
RUN queryCopyDatabase.p.
You cannot copy a database directly in the ABL. It is a shell command.
procopy requires the database to be offline (no server started and no single user client). If the db is live when you try to copy it you will get an error similar to:
If that occurs then a backup can be taken while the DB is online:
Then restore
Then you can connect to the new database (single user -1 or start a server process and connect in shared memory without -1). There is one caveat though. When there are still persistent procedures loaded or class based objects loaded that hold a reference to tables from "mydb", then the DISCONNECT will silently be ignored.