1. Weird Error Using Euphoria Database System (EDS)

I'm hoping one of the devs can tell me how to resolve this issue. Everything was working smoothly all day, until suddenly this started happening:

C:\Euphoria41-32bit\include\std\eds.e:832 in function db_allocate()  
wrong file mode for attempted operation  
    n = 40'(' 
    free_list = <no value> 
    size = <no value> 
    size_ptr = <no value> 
    addr = <no value> 
    free_count = 0 
    remaining = <no value> 
    i = <no value> 
    pos (from inlined routine 'seek' at 134) = <no value> 
    x (from inlined routine 'put4' at 186) = <no value> 
    x (from inlined routine 'put4' at 259) = <no value> 
    pos (from inlined routine 'seek' at 313) = <no value> 
    x (from inlined routine 'put4' at 357) = <no value> 
    pos (from inlined routine 'seek' at 428) = <no value> 
    x (from inlined routine 'put4' at 518) = <no value> 
    pos (from inlined routine 'seek' at 552) = <no value> 
    x (from inlined routine 'put4' at 671) = 44',' 
 
... called from C:\Euphoria41-32bit\include\std\eds.e:2082 in function db_insert()   
    key = 1 
    data = { 
             {72'H',105'i',103'g',104'h',32' ',84'T',101'e',99'c',104'h', 
32' ',70'F',111'o',114'r',109'm',115's',32' ',76'L',76'L',67'C'}, 
             {104'h',105'i',103'g',104'h',116't',101'e',99'c',104'h',102'f', 
111'o',114'r',109'm',115's'}, 
             {} 
           } 
    table_name = {99'c',111'o',109'm',112'p',97'a',110'n',105'i',101'e',115's'} 
    key_string = {10} 
    data_string = {254,3,254,19,81'Q',114'r',112'p',113'q',41')',93']',110'n', 
108'l',113'q',41')',79'O',120'x',123'{',118'v',124'|',41')',85'U',85'U', 
76'L',254,13,113'q',114'r',112'p',113'q',125'}',110'n',108'l',113'q',111'o', 
120'x',123'{',118'v',124'|',254,0} 
    last_part = <no value> 
    remaining = <no value> 
    key_ptr = <no value> 
    data_ptr = <no value> 
    records_ptr = <no value> 
    nrecs = <no value> 
    current_block = <no value> 
    size = <no value> 
    new_size = <no value> 
    key_location = 1 
    new_block = <no value> 
    index_ptr = <no value> 
    new_index_ptr = <no value> 
    total_recs = <no value> 
    r = <no value> 
    blocks = <no value> 
    new_recs = <no value> 
    n = <no value> 
    pos (from inlined routine 'seek' at 101) = <no value> 
    pos (from inlined routine 'seek' at 165) = <no value> 
    pos (from inlined routine 'seek' at 321) = <no value> 
    pos (from inlined routine 'seek' at 500) = <no value> 
    i = 51'3' 
    x (from inlined routine 'put4' at 569) = <no value> 
    pos (from inlined routine 'seek' at 674) = <no value> 
    pos (from inlined routine 'seek' at 811) = <no value> 
    s (from inlined routine 'putn' at 894) = <no value> 
    x (from inlined routine 'put4' at 951) = <no value> 
    pos (from inlined routine 'seek' at 985) = <no value> 
    pos (from inlined routine 'seek' at 1064) = <no value> 
    pos (from inlined routine 'seek' at 1157) = <no value> 
    pos (from inlined routine 'seek' at 1226) = <no value> 
    s (from inlined routine 'putn' at 1350) = <no value> 
    pos (from inlined routine 'seek' at 1381) = <no value> 
 

I'll reboot and see if that helps. (It didn't help.) sad

new topic     » topic index » view message » categorize

2. Re: Weird Error Using Euphoria Database System (EDS)

euphoric said...

I'm hoping one of the devs can tell me how to resolve this issue. Everything was working smoothly all day, until suddenly this started happening:

I'll reboot and see if that helps. (It didn't help.) sad

Here's the test code I threw together. Using DB_LOCK_SHARED for db_open() causes it to crash with "wrong file mode for attempted operation" as you're getting. If you switch to DB_LOCK_EXCLUSIVE, it works fine.

include std/eds.e 
include std/error.e 
include std/filesys.e 
 
constant DB_NAME = "db_test.edb" 
constant DB_TABLE_NAME = "companies" 
constant DB_RECORDS = { 
    { 1, {"High Tech Forms, LLC", "hightechforms", ""} } 
} 
 
procedure main() 
    
    object key, value 
    
    if file_exists( DB_NAME ) then 
        delete_file( DB_NAME ) 
    end if 
    
    if db_create( DB_NAME, DB_LOCK_SHARED ) != DB_OK then 
        error:crash( "db_create() failed." ) 
    end if 
    
    if db_create_table( DB_TABLE_NAME ) != DB_OK then 
        error:crash( "db_create_table() failed." ) 
    end if 
    
    db_close() 
    
    -- 
    -- DB_LOCK_NO        : works 
    -- DB_LOCK_SHARED    : fails 
    -- DB_LOCK_EXCLUSIVE : works 
    -- 
    
    if db_open( DB_NAME, DB_LOCK_EXCLUSIVE ) != DB_OK then 
        error:crash( "db_open() failed." ) 
    end if 
    
    if db_select_table( DB_TABLE_NAME ) != DB_OK then 
        error:crash( "db_select_table() failed." ) 
    end if 
    
    for i = 1 to length( DB_RECORDS ) do 
        
        {key,value} = DB_RECORDS[i] 
        
        if db_insert( key, value ) != DB_OK then 
            error:crash( "db_insert() failed." ) 
        end if 
        
    end for 
    
    db_close() 
    
end procedure 
 
main() 

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: Weird Error Using Euphoria Database System (EDS)

ghaberek said...

Here's the test code I threw together. Using DB_LOCK_SHARED for db_open() causes it to crash with "wrong file mode for attempted operation" as you're getting. If you switch to DB_LOCK_EXCLUSIVE, it works fine.

 
    -- 
    -- DB_LOCK_NO        : works 
    -- DB_LOCK_SHARED    : fails 
    -- DB_LOCK_EXCLUSIVE : works 
    -- 

Same on Phix (thanks Greg for making that test super-easy).

The OE and Phix docs for db_open() both state:

Parameters: lock_method : DB_LOCK_SHARED : (shared lock for read-only access) 
 
DB_LOCK_SHARED is only supported on Unix platforms. It allows you to read the database, but not write anything to it.  

I don't know if the Unix-only bit is still true (I might try testing it tomorrow), but otherwise that agrees with this result.

However the docs (both OE and Phix) go on to say:

If you request DB_LOCK_SHARED on WINDOWS it will be treated as if you had asked for DB_LOCK_EXCLUSIVE. 

yet I cannot see anything to support that claim in the source code of db_open(), and this case, on Windows, it has patently not worked the same as DB_LOCK_EXCLUSIVE.

Are we all in agreement that last sentence should just be deleted?

Pete

new topic     » goto parent     » topic index » view message » categorize

4. Re: Weird Error Using Euphoria Database System (EDS)

petelomax said...

However the docs (both OE and Phix) go on to say:

If you request DB_LOCK_SHARED on WINDOWS it will be treated as if you had asked for DB_LOCK_EXCLUSIVE. 

yet I cannot see anything to support that claim in the source code of db_open(), and this case, on Windows, it has patently not worked the same as DB_LOCK_EXCLUSIVE.

It's around line 1291 in std/eds.e.

https://github.com/OpenEuphoria/euphoria/blob/master/include/std/eds.e#L1291

ifdef WINDOWS then 
    if lock_method = DB_LOCK_SHARED then 
        lock_method = DB_LOCK_EXCLUSIVE 
    end if 
 
end ifdef 
petelomax said...

Are we all in agreement that last sentence should just be deleted?

I don't think it should remove the sentence if the override on Windows is to continue.

Either remove the automatic override and tell the user they have to mind lock types by operating system, or leave the sentence and the bit of code that does the override.

-Greg

new topic     » goto parent     » topic index » view message » categorize

5. Re: Weird Error Using Euphoria Database System (EDS)

ghaberek said...

It's around line 1291 in std/eds.e.

Ah! (I was looking at database.e, doh!)

However, go back 9 lines and we see this: https://github.com/OpenEuphoria/euphoria/blob/master/include/std/eds.e#L1282

 
	if lock_method = DB_LOCK_NO or 
	   lock_method = DB_LOCK_EXCLUSIVE then 
		-- get read and write access, "ub" 
		db = open(path, "ub") 
	else 
		-- DB_LOCK_SHARED, DB_LOCK_READ_ONLY 
		db = open(path, "rb") 
	end if 
 
ifdef WINDOWS then 
	if lock_method = DB_LOCK_SHARED then 
		lock_method = DB_LOCK_EXCLUSIVE 
	end if 
 
end ifdef 

So the docs aren't entirely true. I have added those lines to my database.e, and changed the phix docs to:

If you request DB_LOCK_SHARED on Windows it will get the same lock as DB_LOCK_EXCLUSIVE, but still be read-only. 

Pete

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu