Re: Database.e; db_select(); Can't make it work...
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> Mar 26, 2007
- 594 views
ZNorQ wrote: > > I got a program that have 2 ".edb" files, and I'm trying to use db_select() > to switch between the three. > > When the program starts, it checks to see if the 2 files exists, and if they > don't - it creates them using the db_create(). > > Now, I thought that when using db_create() - this also acts as db_open() and > keeps those databases open, and that I'm then able to use db_select() to > switch between them. > > Example; > > <font color="#330033"><EuCode></font> > <font color="#FF00FF"> sequence </font><font color="#330033">jStatus</font> > <font color="#330033"> jStatus = {}</font> > <font color="#FF0055"> --</font> > <font color="#330033"> jStatus &= db_select(</font><font > color="#00A033">"c:\\Metadata.edb"</font><font color="#330033">)</font> > <font color="#330033"> jStatus &= db_create_table(</font><font > color="#00A033">"TBL_DOCUMENTS"</font><font color="#330033">)</font> > <font color="#FF0055"> --</font> > <font color="#330033"> jStatus &= db_select(</font><font > color="#00A033">"c:\\System.edb"</font><font color="#330033">)</font> > <font color="#330033"> jStatus &= db_create_table(</font><font > color="#00A033">"IDX_DOCUMENTS"</font><font color="#330033">)</font> > <font color="#330033"> jStatus &= db_select_table(</font><font > color="#00A033">"SYS_HEADINGS"</font><font color="#330033">)</font> > <font color="#330033"> jStatus &= db_insert(</font><font > color="#00A033">"TBL_DOCUMENTS"</font><font color="#330033">, </font><font > color="#00A033">"STR_DOC_NO"</font><font color="#330033">, </font><font > color="#00A033">"STR_DOC_TITLE"</font><font color="#330033">)</font> > <font color="#330033"> jStatus &= db_select_table(</font><font > color="#00A033">"SYS_AUTONUMBER"</font><font color="#330033">)</font> > <font color="#330033"> jStatus &= db_insert(</font><font > color="#00A033">"TBL_DOCUMENTS"</font><font color="#330033">, </font><font > color="#993333">{</font><font color="#00A033">"DOC" </font><font > color="#330033">& </font><font color="#00A033">"#"</font><font color="#330033">, > 1</font><font color="#993333">}</font><font color="#330033">)</font> > <font color="#FF0055"> --</font> > <font color="#330033"> jStatus &= db_select(</font><font > color="#00A033">"c:\\Metadata.edb"</font><font color="#330033">)</font> > <font color="#330033"> jStatus &= db_select_table(</font><font > color="#00A033">"TBL_DOCUMENTS"</font><font color="#330033">)</font> > <font color="#330033"></EuCode></font> > > > What happens here is that 2 tables are created in "Metadata.edb", but > the intention was that "TBL_DOCUMENTS" is created in "Metadata.edb", > and "IDX_DOCUMENTS" is created in "System.edb".. > > Can anyone spot what I'm doing wrong? > > Kenneth / ZNorQ Are you sure you succesfully opened the two databases? The doc for db_select() says a database must be opened (using db_create() or db_open()) in order for db_select to succeed. Also note that db_select_table(), likewise, doesn't create a table if it doesn't exist, but does nothing instead, returning the DB_OPEN_FAIL error code. By the way, trying to run your code sippet gave me an error on the first db_insert() statement, as it has 3 arguments instead of 2. Running this code gave me the result you expected:
include database.e ?db_create("Metadata.edb",DB_LOCK_NO) ?db_create("System.edb",DB_LOCK_NO) ?db_select("Metadata.edb") ?db_create_table("TBL_DOCUMENTS") -- ?db_select("System.edb") ?db_create_table("IDX_DOCUMENTS") ?db_select_table("SYS_HEADINGS") ?db_insert("TBL_DOCUMENTS", {"STR_DOC_NO", "STR_DOC_TITLE"}) ?db_select_table("SYS_AUTONUMBER") ?db_insert("TBL_DOCUMENTS", {"DOC" & "#", 1}) -- ?db_select("c:\\Metadata.edb") ?db_select_table("TBL_DOCUMENTS") ?machine_func(26,0)
Of course you'll have to replace the ?s by "jStatus &= ". I did so to see which operations failed and what the db_table_list() were. CChris