Standalone DAL - connection to sqlite db - running web2py

428 views
Skip to first unread message

Ole Martin Maeland

unread,
Nov 18, 2010, 8:36:29 AM11/18/10
to web...@googlegroups.com
Hi,

I am trying to connect to sqlite db that works fine with a small web2py applicaiton.


connection parameters:

>>> dbfolder='C:\web2py\web2py\applications\teqb\databases'

>>> db = dal.DAL('sqlite://storage', folder=dbfolder)

error message:

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python27\lib\site-packages\gluon\dal.py", line 2031, in __init__
    self._logger = Logger(folder)
  File "C:\Python27\lib\site-packages\gluon\dal.py", line 140, in __init__
    self.file = open(os.path.join(folder,name),'a')
IOError: [Errno 22] invalid mode ('a') or filename: 'C:\\web2py\\web2py\x07pplications\teqb\\databases\\sql.log'

any ide how I could get this to work?

regards
Martin

mdipierro

unread,
Nov 18, 2010, 9:06:41 AM11/18/10
to web2py-users
I think you do not have write access on this file/folder

Ole Martin Maeland

unread,
Nov 18, 2010, 9:56:59 AM11/18/10
to web...@googlegroups.com
Hi Massimo,


I have administrator access on the folder. The database is running a small web2py application that is crypted. Do I have to pass the crypt string to the db, or do I have to use administrator password in order to access it.

I reach it by using SQLite Manager..


regards
Martin
--
Hilsen
Ole Martin
Mob: 95227471

mdipierro

unread,
Nov 18, 2010, 10:59:32 AM11/18/10
to web2py-users
I do not understand the meaning of "web2py application that is
crypted"

mart

unread,
Nov 18, 2010, 11:24:06 AM11/18/10
to web2py-users
Hey,

It took me a few tries before getting this to work. So, I see 2 things
that you may want to try to look at:

1) I don't really use windows, but I think the first line is
problematic. (unless more recent windows versions have gotten smarter
about slashes?).

>>> dbfolder='C:\web2py\web2py\applications\teqb\databases'
>>> db = dal.DAL('sqlite://storage', folder=dbfolder)

should be:

>>> dbfolder='C:/web2py/web2py/applications/teqb/databases'
(or you can escape the back slash (C:\\web2py\\web2py\\...))

2) I remember importing DAL was a little finicky (sometimes). SO, you
may want to try drilling down one more level in you import:

instead of
>>> db = dal.DAL('sqlite://storage', folder=dbfolder)

you may want to try:
from <yourPath>.gluon.dal import DAL
>>> db = DAL('sqlite://storage', folder=dbfolder)


I do the following without any problems on Mac, linux and windows: I
have 2 instances of web2py, some both running on the same machine, so
stand alone is renamed with "blue" prefixes (blueDAL, bluedb,
blueTHIS, blueTHAT, etc. and gluon is renamed to blueSQL in case they
run 2 different versions of web2py, I want to quickly and visually set
them apart when reading script.


tail,head = os.path.split(sys.argv[0])

dataFiles = ["storage.sqlite",
"sql.log"]
dbFolder = "{0}/blueLite/db_storage".format(tail)

try:
for f in os.listdir(dbFolder):
if ".table" in f:
fTable = "{0}/{1}".format(dbFolder,f)
os.remove(fTable)
print("removed {0}".format(fTable))
for dFile in dataFiles:
os.remove("{0}/blueLite/db_storage/{1}".format(tail,dFile))
print("removed {0}/blueLite/db_storage/
{1}".format(tail,dFile))
except Exception as errObj:
print(str(errObj))

from blueLite.pyUtils.sql.blueSQL.dal import DAL as blueDal
from blueLite.pyUtils.sql.blueSQL.dal import SQLField
bluedb = blueDal("sqlite://storage.sqlite", folder="{0}/blueLite/
db_storage".format(tail))
bluedb.define_table('cmdObjects',
SQLField('name'),
SQLField('pyModule'),
SQLField('pyPath'),
SQLField('cmdProperties','blob'),
SQLField('dict_objCmd','blob'),
SQLField('dfo_objCmd', 'blob'),
SQLField('etree_objCmd','blob'))
bluedb.commit()

Then I pass bluedb to all other classes which is why I use the full
path when pointing to the DB folder (NEVER relative).
hope it helps.


Mart :)

Ole Martin Maeland

unread,
Nov 19, 2010, 10:36:14 AM11/19/10
to web...@googlegroups.com
thanks !
Reply all
Reply to author
Forward
0 new messages