Substring in new DAL

18 views
Skip to first unread message

rfx_labs

unread,
Dec 13, 2009, 5:14:20 PM12/13/09
to web2py-users
Hi Massimo,

this doesn't work any more:
nw.ekartikel.Name[4:]

File "/PATH/web2py/gluon/sql.py", line 2742, in __getslice__
s = self._db._adapter.SUBSTRING(d)
TypeError: SUBSTRING() takes exactly 4 arguments (2 given)


Martin

rfx_labs

unread,
Dec 13, 2009, 5:26:37 PM12/13/09
to web2py-users
this is the patch for this:

@@ -151,7 +151,7 @@
return 'Random()'
def NOT_NULL(self,default):
return 'NOT NULL DEFAULT %s' % default
- def SUBSTRING(self,fieldname,pos,lenght):
+ def SUBSTRING(self,fieldname,pos,length):
return 'SUBSTR(%s,%s,%s)' % (fieldname, pos, length)
def PRIMARY_KEY(self,key):
return 'PRIMARY KEY(%s)' % key
@@ -386,7 +386,7 @@
}
def RANDOM(self):
return 'RAND()'
- def SUBSTRING(self,fieldname,pos,lenght):
+ def SUBSTRING(self,fieldname,pos,length):
return 'SUBSTRING(%s,%s,%s)' % (fieldname, pos, length)
def DROP(self,table,mode):
# breaks db integrity but without this mysql does not drop
table
@@ -605,7 +605,7 @@
return 'LEFT OUTER JOIN'
def RANDOM(self):
return 'NEWID()'
- def SUBSTRING(self,fieldname,pos,lenght):
+ def SUBSTRING(self,fieldname,pos,length):
return 'SUBSTRING(%s,%s,%s)' % (fieldname, pos, length)
def PRIMARY_KEY(self,key):
return 'PRIMARY KEY CLUSTERED (%s)' % key
@@ -731,7 +731,7 @@
return 'RAND()'
def NOT_NULL(self,default):
return 'DEFAULT %s NOT NULL', default
- def SUBSTRING(self,fieldname,pos,lenght):
+ def SUBSTRING(self,fieldname,pos,length):
return 'SUBSTRING(%s,%s,%s)' % (fieldname, pos, length)
def DROP(self,table,mode):
return ['DROP TABLE %s %s;' % (table, mode), 'DROP GENERATOR
GENID_%s;' % table]
@@ -2738,8 +2738,8 @@
def __getslice__(self, start, stop):
if start < 0 or stop < start:
raise SyntaxError, 'not supported: %s - %s' % (start,
stop)
- d = dict(field=str(self), pos=start + 1, length=stop - start)
- s = self._db._adapter.SUBSTRING(d)
+ d = dict(fieldname=str(self), pos=start + 1, length=stop -
start)
+ s = self._db._adapter.SUBSTRING(**d)
return Expression(s, 'string', self._db)

def __getitem__(self, i):

mdipierro

unread,
Dec 13, 2009, 6:47:47 PM12/13/09
to web2py-users
thanks! uploading to trunk.

Massimo
Reply all
Reply to author
Forward
0 new messages