TOPIC: Distinguish my app tables...
#584
Distinguish my app tables... 3 Years, 7 Months ago
I would like to use a trigger to mantain a table with all my application tables. The idea is simple: when you create a new table, its table number is stored in another table named, for example, 'myapp_tables'. In this way, I could display only the tables of my app by quering myapp_tables.

myapp_tables is defined with:

create myapp_tables (table, Tablename_DERIVED) key(table)

For the derived field I have this rule:

Code:

Rule_tablename_DERIVED
function()
{
rec = false
try rec = Query1("tables where table = " $ .table)
if rec isnt false
return rec.tablename
return ""
}



Here is the trigger:

Code:

Trigger_tables
function (t, oldrec, newrec)
{
if oldrec is false and newrec isnt false
{ //NEW TABLE ADDED
t.QueryDo("insert {table: " $ newrec.table $ " tablename: } into myapp_tables")
}
else if oldrec isnt false and newrec is false
{ //TABLE DELETED
t.QueryDo("delete myapp_tables where table = " $ oldrec.table)
}
}





But if I create this trigger, then when I create a new table, it appears this error:

query: sudb.cpp:191: assertion failure: t > 0

What it means?
 
 
Mauro
 
#585
Re:Distinguish my app tables... 3 Years, 7 Months ago
The trigger seems to have an error with tablename: because there is no value and because myapp_tables does not have a tablename field. (We would normally use QueryOutput but insert should be ok too.)

Unfortunately, this approach will not work because triggers are not called for schema changes. I can not remember exactly why this was done. Part of the reason may be that schema changes are done "outside" of transactions.

However, the error you are getting sounds like it is trying to run the trigger (but it is failing because there is no transaction).

I could not make the error happen - I tried creating and deleting tables, but the trigger did not get called. (I put a Print in it.)

Post edited by: andrew, at: 2007/01/24 19:40
 
 
andrew
 
#587
Re:Distinguish my app tables... 3 Years, 7 Months ago
andrew wrote:
[...]I could not make the error happen - I tried creating and deleting tables, but the trigger did not get called. (I put a Print in it.)Maybe you are not able to make the error happen because you haven't tried to create the table in the QueryView. That error appears to me when I try to create a table in the QueryView with a 'create' statement.
Anyway, there could be some other way to distinguish between my tables and those of Suneido? I'm working on an ER diagram generator, and it would be very nice if I could have directly my app tables.
 
 
Mauro
 
#588
Re:Distinguish my app tables... 3 Years, 7 Months ago
I did create & destroy tables from QueryView.

Table numbers are assigned sequentially so the early numbers will be system tables, but since some tables are created dynamically, they may have numbers mixed in with your application tables.

The system tables do not change that often so it might be feasible to make a list of them.

Did you look at Cookbook > Using Graphviz from Suneido

Our applications use standard prefixes on the table names so it is a little
easier.
 
 
andrew
 
#590
Re:Distinguish my app tables... 3 Years, 7 Months ago
Yes, I'm using GraphViz, but in a way a little more sophisticated. I want to generate a classic ER diagram, with relationships, cardinality, attributes, etc.
For now, I use a special table with records related to my application tables. Then this table is used by a function 'ERdiagram' that generates a 'schema.png' file with the ER diagram, and then display it in your preferred image viewer program.

When I'm done will post the code. ;)

P.S.: in my app I don't use prefixes for my table names. I don't like to use a prefix each time I have to refer to a table of my app, inside a query. I'm a spoiled child. :D

Post edited by: Mauro, at: 2007/01/25 00:15
 
 
Mauro