Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Database Locations — Gideros Forum

Database Locations

CyberienceCyberience Member
edited March 2013 in General questions
Got a Quick question on where to store my Database,
Do I store it in |R| location? But htis is read only. so do I need to copy it to the |D| folder for use?

Regards
REAL programmers type copy con filename.exe
---------------------------------------
Tagged:

Comments

  • atilimatilim Maintainer
    edited March 2013 Accepted Answer
    If you're going to modify your database (I think you need to), then you should copy the file from |R| to |D|. But I realized that neither os.* nor lfs.* provides a file copy function. If you want, you can use this implementation:
    local function copy(src, dst)
    	local srcf = io.open(src, "rb")
    	local dstf = io.open(dst, "wb")
     
    	local size = 2^13      -- good buffer size (8K)
    	while true do
    		local block = srcf:read(size)
    		if not block then break end
    		dstf:write(block)
    	end
     
    	srcf:close()
    	dstf:close()
    end
    Also it's better to check if you have already copied the file previously with this function:
    local function exists(file)
    	local f = io.open(file, "rb")
    	if f == nil then
    		return false
    	end
    	f:close()
    	return true
    end
    Now you can copy your database file:
    if not exists("|D|database.db") then
    	copy("database.db", "|D|database.db")
    end

    Likes: hgvyas123

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.