1. EDS:: select or create table
- Posted by K_D_R Feb 10, 2012
- 1648 views
I am having a wreck of a heck of a time trying to figure out how to create a database after db_table_list returns and a NO_TABLE error.
If the db has a table there is no problem. But if there is no table everything freezes up pronto.
This is my latest failing effort:
-- select or create table procedure select_or_create_table() db_banner("Select Table") sequence answer = {} tables = {} object dbtblst dbtblst = db_table_list() if atom(dbtblst) then if dbtblst = NO_TABLE then answer = delete_trailing_white(key_gets(" ", {})) end if else for i = 1 to length(dbtblst) do tables = update_history(tables, sprintf("%s", {dbtblst[i]})) end for answer = delete_trailing_white(key_gets("", tables)) end if if length(answer) != 0 then if db_select_table(answer)!= DB_OK then if db_create_table(answer) != DB_OK then db_banner("tb") any_key("Failed to create/select table! ") end if end if tables = update_history(tables, answer) end if end procedure
Any suggestions will be much appreciated.
Regards, Kenneth Rhodes
2. Re: EDS:: select or create table
- Posted by mattlewis (admin) Feb 10, 2012
- 1593 views
I am having a wreck of a heck of a time trying to figure out how to create a database after db_table_list returns and a NO_TABLE error.
If the db has a table there is no problem. But if there is no table everything freezes up pronto.
There's a lot of stuff in there that I don't recognize, like key_gets(). Are you sure that answer is taking the value that you think it is? Can you be more specific about what "freezes up" means?
Matt
3. Re: EDS:: select or create table
- Posted by K_D_R Feb 10, 2012
- 1583 views
I am having a wreck of a heck of a time trying to figure out how to create a database after db_table_list returns and a NO_TABLE error.
If the db has a table there is no problem. But if there is no table everything freezes up pronto.
There's a lot of stuff in there that I don't recognize, like key_gets(). Are you sure that answer is taking the value that you think it is? Can you be more specific about what "freezes up" means?
Matt
Key_gets was not the problem. The routine was freezing up after displaying "Select Table" on the top-line with the cursor blinking, but not accepting any keyboard input. It should have accepted the name of a table typed in by the user. The following routine works. The question now is why does the code testing dttblst for atom status and "NO_TABLE" status fail? What is the proper use of NO_TABLE?
procedure select_or_create_table() db_banner("Select Table") sequence answer = {} -- tmp = {} tables = {} object dbtblst dbtblst = db_table_list() -- if atom(dbtblst) then -- if dbtblst = NO_TABLE then -- answer = delete_trailing_white(key_gets(" ", {})) -- end if -- else -- for i = 1 to length(dbtblst) do -- tables = update_history(tables, sprintf("%s", {dbtblst[i]})) -- end for -- answer = delete_trailing_white(key_gets("", tables)) -- -- end if if length(dbtblst) < 1 then answer = delete_trailing_white(key_gets("",{})) else for i = 1 to length(dbtblst) do tables = update_history(tables, sprintf("%s", {dbtblst[i]})) end for answer = delete_trailing_white(key_gets("", tables)) end if if length(answer) != 0 then if db_select_table(answer)!= DB_OK then if db_create_table(answer) != DB_OK then db_banner("tb") any_key("Failed to create/select table! ") end if end if tables = update_history(tables, answer) end if end procedure
Your assistance is appreciated.
Kenneth Rhodes
4. Re: EDS:: select or create table
- Posted by DerekParnell (admin) Feb 10, 2012
- 1529 views
Key_gets was not the problem.
I'm not convinced that you are correct with this assertion. What does key_gets() do?
Could the problem be that you called key_gets() differently. When using it after the NO_TABLE test, you called it with a string containing one blank ... key_gets(" ", {}) but when calling it after the length(dbtblst) < 1 test, you callied with an empty string key_gets("",{}).
Is that significant?
5. Re: EDS:: select or create table
- Posted by jimcbrown (admin) Feb 10, 2012
- 1473 views
Key_gets was not the problem.
I'm not convinced that you are correct with this assertion. What does key_gets() do?
I suspect that this is the key_gets() routine from ed.ex
Could the problem be that you called key_gets() differently. When using it after the NO_TABLE test, you called it with a string containing one blank ... key_gets(" ", {}) but when calling it after the length(dbtblst) < 1 test, you callied with an empty string key_gets("",{}).
Is that significant?
My understanding is that this is very significant. In the former, a hot key is passed in (so pressing spacebar triggers a hot key), but in the latter, no hot keys are passed in.
db table names generally don't include spaces, however, if a space was entered then an empty string would be returned and assigned to answer.
The functional code suggests that db_table_list() is never returning an atom.
6. Re: EDS:: select or create table
- Posted by K_D_R Feb 10, 2012
- 1503 views
[quote jimcbrown]
Key_gets was not the problem.
I'm not convinced that you are correct with this assertion. What does key_gets() do?
I suspect that this is the key_gets() routine from ed.ex
Could the problem be that you called key_gets() differently. When using it after the NO_TABLE test, you called it with a string containing one blank ... key_gets(" ", {}) but when calling it after the length(dbtblst) < 1 test, you callied with an empty string key_gets("",{}).
Is that significant?
My understanding is that this is very significant. In the former, a hot key is passed in (so pressing spacebar triggers a hot key), but in the latter, no hot keys are passed in.
The list of hot-keys is optional. Key_gets is the same routine that ed.ex uses to select/open new files, command_history, file_history, as well as the get_escape routine which uses hot keys for ed.ex 's menu etc. - but you are right as far as the difference between "" and " " being significant and in fact causes the same "freeze" in the block of code that other wise functions properly.
db table names generally don't include spaces, however, if a space was entered then an empty string would be returned and assigned to answer.
So, I should check for the return of a space in answer and reset the input routine ( loop back ), if necessary, right?
The functional code suggests that db_table_list() is never returning an atom.
BINGO! When I run the first block of code without evaluating dbtblst for atom status on a new db which has no table, I get a "true false condition must be an atom" for the line:
if dbtblst = NO_TABLE then
Shouldn't NO_Table be an atom?
Regards, Kenneth Rhodes
7. Re: EDS:: select or create table
- Posted by DerekParnell (admin) Feb 11, 2012
- 1453 views
BINGO! When I run the first block of code without evaluating dbtblst for atom status on a new db which has no table, I get a "true false condition must be an atom" for the line:
if dbtblst = NO_TABLE then
Shouldn't NO_Table be an atom?
NO_TABLE is an atom. However, according to the documentation, db_table_list() returns a sequence that contains a list of table names. If this sequence is empty, there are no tables in the database.
The NO_TABLE error code is returned only by those functions that can take a table name as a parameter and the supplied table name is not known in the current database. The db_table_list() function does not accept a table name as a parameter so it does not return NO_TABLE. Also, as a database can legally contain no tables, it is never an error condition for db_table_list() to return an empty list. The NO_TABLE is an error condition so its not appropriate for db_table_list() to return that code.
8. Re: EDS:: NO_TABLE, db_table_list()
- Posted by K_D_R Feb 11, 2012
- 1382 views
BINGO! When I run the first block of code without evaluating dbtblst for atom status on a new db which has no table, I get a "true false condition must be an atom" for the line:
if dbtblst = NO_TABLE then
Shouldn't NO_Table be an atom?
NO_TABLE is an atom. However, according to the documentation, db_table_list() returns a sequence that contains a list of table names. If this sequence is empty, there are no tables in the database.
The documentation currently makes no reference to an empty sequence. I believe the documentation should be improved by appending your last sentence above to the description of what db_table_list() returns:
Returns: A sequence, of all the table names in the current database. Each element of this sequence is a sequence, the name of a table. If this sequence is empty, there are no tables in the database.
The NO_TABLE error code is returned only by those functions that can take a table name as a parameter and the supplied table name is not known in the current database. ... The db_table_list() function does not accept a table name as a parameter so it does not return NO_TABLE.
I somehow miss the above information in the documentation. Given the current state of the documentation search facilities, it could be there and easily missed. What I do see is this:
8.28.3.4 NO_TABLE include std/eds.e namespace eds public enum NO_TABLE no table was found.
No table was found. Certainly, no table was found by db_table_list() when the current db had no tables. Shouldn't that statement be replaced by a more accurate description, such as Derek has provided above?:
8.28.3.4 NO_TABLE include std/eds.e namespace eds public enum NO_TABLE The ##NO_TABLE## error code is returned only by those functions that can take a table name as a parameter and the supplied table name is not known in the current database.
Also, as a database can legally contain no tables, it is never an error condition for db_table_list() to return an empty list. The NO_TABLE is an error condition so its not appropriate for db_table_list() to return that code.
Following that logic: as a database can legally not have a specific table sought by a certain function, it would not be an error to return an empty sequence, but an error code is returned instead.
A database can legally contain no tables and it can legally contain no tables with a name specified in the parameters of a function.
Isn't it is just as much of an error not to find any table at all in response to a query for a list of tables as it is not to find a specific table in response to a query for a table with a particular name? If there is a benefit in returning the NO_TABLE error code in the latter case, shouldn't that benefit be extended to the former case?
Jiri Babor did not suffer fools gladly. He commented a block of code in one of his programs:
-- in case of idiots
I smiled, knowing Jiri was looking out for me.
Regards, Kenneth Rhodes
9. Re: EDS:: NO_TABLE, db_table_list()
- Posted by DerekParnell (admin) Feb 11, 2012
- 1455 views
The documentation currently makes no reference to an empty sequence.
That is true. However I didn't think it would have to as an empty sequence is a list of all the tables in a database that contains no tables. I thought it was self evident as in ... 2 entries means there are 2 tables, 1 entry means that there is one table and zero entries therefore naturally means that there are no tables.
However, for Jiri's sake, I'll add this to the documentation.
The NO_TABLE error code is returned only by those functions that can take a table name as a parameter and the supplied table name is not known in the current database. ... The db_table_list() function does not accept a table name as a parameter so it does not return NO_TABLE.
I somehow miss the above information in the documentation. Given the current state of the documentation search facilities, it could be there and easily missed. What I do see is this:
8.28.3.4 NO_TABLE include std/eds.e namespace eds public enum NO_TABLE no table was found.
No table was found. Certainly, no table was found by db_table_list() when the current db had no tables. Shouldn't that statement be replaced by a more accurate description, such as Derek has provided above?:
The NO_TABLE value should more accurately be described as the specifically requested table was not found.
Also, as a database can legally contain no tables, it is never an error condition for db_table_list() to return an empty list. The NO_TABLE is an error condition so its not appropriate for db_table_list() to return that code.
Following that logic: as a database can legally not have a specific table sought by a certain function, it would not be an error to return an empty sequence, but an error code is returned instead.
A database can legally contain no tables and it can legally contain no tables with a name specified in the parameters of a function.
Isn't it is just as much of an error not to find any table at all in response to a query for a list of tables as it is not to find a specific table in response to a query for a table with a particular name? If there is a benefit in returning the NO_TABLE error code in the latter case, shouldn't that benefit be extended to the former case?
I'm not sure that I agree with this logic. Asking for a list of all tables contained within a database and receiving a list with nothing in it is simply NOT an error condition. But, for example, asking to delete a record from a specific table and that table not existing IS an error condition. I say this because the first function can complete its requested task (listing all known tables), and the second cannot complete its task.
10. Re: EDS:: NO_TABLE, db_table_list()
- Posted by K_D_R Feb 12, 2012
- 1354 views
The NO_TABLE error code is returned only by those functions that can take a table name as a parameter and the supplied table name is not known in the current database. ... The db_table_list() function does not accept a table name as a parameter so it does not return NO_TABLE.
I somehow miss the above information in the documentation. Given the current state of the documentation search facilities, it could be there and easily missed. What I do see is this:
8.28.3.4 NO_TABLE include std/eds.e namespace eds public enum NO_TABLE no table was found.
No table was found. Certainly, no table was found by db_table_list() when the current db had no tables. Shouldn't that statement be replaced by a more accurate description, such as Derek has provided above?:
The NO_TABLE value should more accurately be described as the specifically requested table was not found.
Thank you.
The documentation currently makes no reference to an empty sequence.
That is true. However I didn't think it would have to as an empty sequence is a list of all the tables in a database that contains no tables. I thought it was self evident as in ... 2 entries means there are 2 tables, 1 entry means that there is one table and zero entries therefore naturally means that there are no tables.
However, for Jiri's sake, I'll add this to the documentation.
"A list of all the tables in a database that contains no tables", eh. You may as well rename the language , "Obfuscoria".
This is what should be self-evident to you. This whole imbroglio was brought about because the documentation had the error code NO_TABLE listed with the sole description "No table was found", and absolutely no other reference as to how it should be used. Therefore, it seemed self evident to me that when after a call to db_table_list() "no table was found" in the database, then NO_TABLE was an appropriately descriptive error code for the circumstance at hand.
So for Jiri's sake, I thank you again, in advance, for improving the documentation.
Regards, Kenneth Rhodes