Sw4   >   Sql   >   Database Administration
The StudioWorks
simplifies the process of preparing and maintaining SQL databases.In an ideal world all SQL database management systems would use the same SQL syntax, but we live in an imperfect world. The StudioWorks DB Admin classes overcome the SQL database differences by allowing us to customize the SQL text and methods for accomplishing various tasks for each RDBMS.
The StudioWorks DBAdmin classes performs tasks such:
The DBAdmin tools are able to accomplish the above using the meta-data which you add to the schema classes using the SQL Meta-Data Editor.
The DB Admin tools are accessed via the
tab of the .All of the DB Admin functions can be accessed by your application through the oDBAdmin object. You simply create an object variable, point it to oDBAdmin, sent it an $initalize(pSessionRow) message, and you are in business. All of the public methods of oDBAdmin are at your disposal. You can create/sync tables, drop tables, drop columns, rename table, rename columns, etc., etc.
The various DB Admin windows are described in the next sections.If you create a new database and want to move data from an existing StudioWorks application based database to the new database the
is your one click ticket.To copy data from one database to another.
The sync operation always sets/resets the primary key counters. This ensures that the counter for each table will be greater than the maximum primary key value in each table after you copy in the new data.
The copy operation simply inserts the data. It does not check for existing records. The tables should alway be empty.
If the sync succeeds but then the copy fails part way through you can select and right-click on the tables in the target list and
You can also right-click and select . to completely delete the selected tables in the target database.The
tab lets you look at all the schemas and columns in your application and the tables and columns in the database.When you select a Table Name list, and the database table's columns are list in the Column Name list.
in the left list, the are listed in the second list. If a matching table already exists in the database it is selected in the theIf you click the Sync Database to Match Selected Schemas, StudioWorks will do just that. If a table is missing it is created, if a column is missing it is added, if the column datatype has changed it is altered, if there is an extra column you are given a warning, if an index is missing it is added, if a foreign key constraint is missing it is added, etc. Each time the DB Admin tool sync's a table it also sets the primary key counter.
The button will loop through the selected schemas which have checked in the meta-data for the primary key column, and will check for a zero value primary key record and if not found insert one. Zero pkey records are used optional foreign key joins.The DB Admin -
tab simply lists the database tables and the indexes for the table you select.You can right-click
A sync operation will readd meta-data based indexes you delete. selected indexes.The DB Admin -
tab lists the database tables, the maximum primary key value for each table, and the current primary key counter value.You can right-click
to set a counter to a specific value.Clicking the Reset Counter Values button at the bottom of the window will reset the counters to one above the max value or each selected table.
A sync operation resets a tables primary key counter.The DB Admin -
tab simply lists the database tables and the constraints for the table you select.You can right-click
selected constraints.A sync operation will readd meta-data based constraints you delete.
The Omnis data file does not support constraints. (other than not null)
All RDMBSs that I know of support foreign key constraints.
Some RDBMSs support CHECK constraints. (FrontBase and PostgreSQL)
The DB Admin -
tab lists the App users (in the usr table) the Database Users, and the database tables.Code was written and tested for FrontBase for adding Database users which match the App users, and granting them privileges for selected tables.
The original intent was that a Database user would be added for each App user and the Database user's PRIVILEGES for each table would match their schema classes settings in their security profile. (canview, caninsert, canedit, candelete).
Keeping Database users sync'd with App users is a lot of work. Every time you add an App user or change an App user's security settings you have to sync the Database users.
Currently all of the StudioWorks developers use the tablesownerlogon technique, so I have not spent further time developing the code for synchronizing Database users with App users. The tab is currently disabled in the DB Admin window.You can use the
window of the tool for entering and executing SQL.I use the
window for testing and editing long SQL queries that for some reason aren't working.There are some handy features in the StudioWorks
window that you should be aware of:SELECT TownCityName, StateProvName, CountryName
FROM Towncity, Stateprov, Country
WHERE Towncity.Stateprov_fkey = StateProv_pkey
AND Towncity.Country_fkey = Country_pkey
When you close the window the SQL history is saved to the local_prefs.df1 file.
When you open the window it is restored.The DB Admin -
You can right-click tab lists the database tables and fetches the first batch of records the table you select. a record in a table.The DB Admin -
tab lists the reserved words which StudioWorks uses to audit your table and column names.Each time a sync operation is done, StudioWorks first audits the table and column names of all the selected tables. If a reserved word is used in a table or column name, an error is logged and the sync operation is halted.
This saves you the grief of wondering why a perfectly good looking SQL statement fails because it use a SQL reserved word for a table or column name. (I know from experience, I and others have lost hours trying to solve these types of SQL errors.)The Query Builder is a handy window that helps you build and modify query classes.
Base on meta-data Query Builder makes its best guess on the extra query text to join tables by way of their foreign key relationships.
Some of the advantages the Query Builder window are: