[web2py] Re: Reference field to string field in a keyed table. MSSQL

2013-03-04 Thread Dmitry Mosin
It works!
Thank you, Denes! 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Reference field to string field in a keyed table. MSSQL

2013-03-03 Thread DenesL

My apologies for the typo:

  table_name = tablename,


On Saturday, March 2, 2013 12:31:54 PM UTC-5, Dmitry Mosin wrote:

 Hello, friends

 Now it looks like

 type 'exceptions.NameError' global name 'table_name' is not defined

 806.
 807.
 808.
 809.
 810.
 811.

 812.
 813.
 814.
 815.

 ftype = ftype + \
 types['reference FK'] % dict(
 constraint_name = constraint_name, # 
 should be quoted
 foreign_key = '%s (%s)' % (rtablename,
rfieldname),
 table_name = table_name,

 field_name = field_name,
 on_delete_action=field.ondelete)
 else:
 # make a guess here for circular references



 Thank you for your time


 суббота, 2 марта 2013 г., 21:17:27 UTC+6 пользователь Massimo Di Pierro 
 написал:

 Fixed. please check it. Thanks Denes.

 On Saturday, 2 March 2013 06:12:31 UTC-6, DenesL wrote:

 It seems that the original code for keyed tables was wrongly patched at 
 some point in time.
 That part of the code should read:

   ftype = ftype + \
   types['reference FK'] % dict(
   constraint_name = constraint_name,
   foreign_key = '%s (%s)' % (rtablename,
  rfieldname),
   table_name = table_name,
   field_name = field_name,
   on_delete_action=field.ondelete)


 Denes.

 On Saturday, March 2, 2013 12:11:03 AM UTC-5, Dmitry Mosin wrote:

 Hi

 There is another exception

 type 'exceptions.KeyError' 'field_name'*File 
 /var/www/py/web2py/gluon/dal.py in create_table at line 811*

 806.
 807.
 808.
 809.
 810.
 811.

 812.
 813.
 814.
 815.

 ftype = ftype + \
 types['reference FK'] % dict(
 constraint_name = constraint_name, # 
 should be quoted
 foreign_key = '%s (%s)' % (rtablename,
rfieldname),
 on_delete_action=field.ondelete)

 else:
 # make a guess here for circular references
 if referenced in db:
 id_fieldname = db[referenced]._id.name




-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Reference field to string field in a keyed table. MSSQL

2013-03-02 Thread DenesL
It seems that the original code for keyed tables was wrongly patched at 
some point in time.
That part of the code should read:

  ftype = ftype + \
  types['reference FK'] % dict(
  constraint_name = constraint_name,
  foreign_key = '%s (%s)' % (rtablename,
 rfieldname),
  field_name = field_name,
  on_delete_action=field.ondelete)


Denes.

On Saturday, March 2, 2013 12:11:03 AM UTC-5, Dmitry Mosin wrote:

 Hi

 There is another exception

 type 'exceptions.KeyError' 'field_name'*File 
 /var/www/py/web2py/gluon/dal.py in create_table at line 811*

 806.
 807.
 808.
 809.
 810.
 811.

 812.
 813.
 814.
 815.

 ftype = ftype + \
 types['reference FK'] % dict(
 constraint_name = constraint_name, # 
 should be quoted
 foreign_key = '%s (%s)' % (rtablename,
rfieldname),
 on_delete_action=field.ondelete)

 else:
 # make a guess here for circular references
 if referenced in db:
 id_fieldname = db[referenced]._id.name




-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Reference field to string field in a keyed table. MSSQL

2013-03-02 Thread Massimo Di Pierro
Fixed. please check it. Thanks Denes.

On Saturday, 2 March 2013 06:12:31 UTC-6, DenesL wrote:

 It seems that the original code for keyed tables was wrongly patched at 
 some point in time.
 That part of the code should read:

   ftype = ftype + \
   types['reference FK'] % dict(
   constraint_name = constraint_name,
   foreign_key = '%s (%s)' % (rtablename,
  rfieldname),
   table_name = table_name,
   field_name = field_name,
   on_delete_action=field.ondelete)


 Denes.

 On Saturday, March 2, 2013 12:11:03 AM UTC-5, Dmitry Mosin wrote:

 Hi

 There is another exception

 type 'exceptions.KeyError' 'field_name'*File 
 /var/www/py/web2py/gluon/dal.py in create_table at line 811*

 806.
 807.
 808.
 809.
 810.
 811.

 812.
 813.
 814.
 815.

 ftype = ftype + \
 types['reference FK'] % dict(
 constraint_name = constraint_name, # 
 should be quoted
 foreign_key = '%s (%s)' % (rtablename,
rfieldname),
 on_delete_action=field.ondelete)

 else:
 # make a guess here for circular references
 if referenced in db:
 id_fieldname = db[referenced]._id.name




-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Reference field to string field in a keyed table. MSSQL

2013-03-02 Thread Dmitry Mosin
Hello, friends

Now it looks like

type 'exceptions.NameError' global name 'table_name' is not defined

806.
807.
808.
809.
810.
811.

812.
813.
814.
815.

ftype = ftype + \
types['reference FK'] % dict(
constraint_name = constraint_name, # should 
be quoted
foreign_key = '%s (%s)' % (rtablename,
   rfieldname),
table_name = table_name,

field_name = field_name,
on_delete_action=field.ondelete)
else:
# make a guess here for circular references



Thank you for you time


суббота, 2 марта 2013 г., 21:17:27 UTC+6 пользователь Massimo Di Pierro 
написал:

 Fixed. please check it. Thanks Denes.

 On Saturday, 2 March 2013 06:12:31 UTC-6, DenesL wrote:

 It seems that the original code for keyed tables was wrongly patched at 
 some point in time.
 That part of the code should read:

   ftype = ftype + \
   types['reference FK'] % dict(
   constraint_name = constraint_name,
   foreign_key = '%s (%s)' % (rtablename,
  rfieldname),
   table_name = table_name,
   field_name = field_name,
   on_delete_action=field.ondelete)


 Denes.

 On Saturday, March 2, 2013 12:11:03 AM UTC-5, Dmitry Mosin wrote:

 Hi

 There is another exception

 type 'exceptions.KeyError' 'field_name'*File 
 /var/www/py/web2py/gluon/dal.py in create_table at line 811*

 806.
 807.
 808.
 809.
 810.
 811.

 812.
 813.
 814.
 815.

 ftype = ftype + \
 types['reference FK'] % dict(
 constraint_name = constraint_name, # 
 should be quoted
 foreign_key = '%s (%s)' % (rtablename,
rfieldname),
 on_delete_action=field.ondelete)

 else:
 # make a guess here for circular references
 if referenced in db:
 id_fieldname = db[referenced]._id.name




-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Reference field to string field in a keyed table. MSSQL

2013-03-01 Thread DenesL

Sorry, I misunderstood when you said:

m_dsc_clients - is not a legacy table and defined in db.py, 


This line in dal.py is wrong (it was recently fixed in trunk):

 if rfieldname in hasattr(rtable,'_primarykey') \

it should read:

if rfieldname in rtable._primarykey \


You can either update it manually or use latest trunk.



On Thursday, February 28, 2013 11:41:29 PM UTC-5, Dmitry Mosin wrote:

 eyed tables can only reference (or be referenced by) other keyed tables.


 But this table is keyed, isn't it?

 db.define_table('m_dsc_
 clients',
 Field('cn','string'),
 Field('cardid','reference m_dsc_cards'),
 primarykey=['cn'],
 )




-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Reference field to string field in a keyed table. MSSQL

2013-03-01 Thread Dmitry Mosin


 Sorry, I misunderstood when you said:
 m_dsc_clients - is not a legacy table and defined in db.py, 

It's my fault, the explanation was a bit unclear.
 


 This line in dal.py is wrong (it was recently fixed in trunk):

  if rfieldname in hasattr(rtable,'_primarykey') \

 it should read:

 if rfieldname in rtable._primarykey \


 You can either update it manually or use latest trunk.


Thank you! 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Reference field to string field in a keyed table. MSSQL

2013-03-01 Thread Dmitry Mosin
Hi

There is another exception

type 'exceptions.KeyError' 'field_name'*File 
/var/www/py/web2py/gluon/dal.py in create_table at line 811*

806.
807.
808.
809.
810.
811.

812.
813.
814.
815.

ftype = ftype + \
types['reference FK'] % dict(
constraint_name = constraint_name, # should 
be quoted
foreign_key = '%s (%s)' % (rtablename,
   rfieldname),
on_delete_action=field.ondelete)

else:
# make a guess here for circular references
if referenced in db:
id_fieldname = db[referenced]._id.name


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Reference field to string field in a keyed table. MSSQL

2013-02-28 Thread Dmitry Mosin


 option 3 is the closest one since references between keyed tables *must* 
 use tablename.fieldname,
 but migrate=False should be added to each table unless it is specified in 
 the DB definition.

 A small clarification

m_dsc_cards - is a legacy table, it can't be changed,
of course 'migrate=False, fake_migrate=True' are set
a primary key is cardid, type is varchar(32)

m_dsc_clients - is not a legacy table and defined in db.py, 
and it must have a reference to m_dsc_cards by m_dsc_cards.cardid

The result of either an exception or the wrong type of field

How can I solve the point?

(sorry for bad english)

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Reference field to string field in a keyed table. MSSQL

2013-02-28 Thread Dmitry Mosin


*File /var/www/py/web2py/gluon/dal.py in create_table at line 772* 
 Function argument list 

(self=gluon.dal.MSSQLAdapter object, table=Table m_dsc_clients (...), 
migrate=True, fake_migrate=False, polymodel=None)
 Code listing 

767.
768.
769.
770.
771.
772.

773.
774.
775.
776.

if hasattr(table,'_primarykey'):
rtablename,rfieldname = referenced.split('.')
rtable = db[rtablename]
rfield = rtable[rfieldname]
# must be PK reference or unique
if rfieldname in hasattr(rtable,'_primarykey') \
or rfield.unique:

ftype = types[rfield.type[:9]] % \
dict(length=rfield.length)
# multicolumn primary key reference?
if not rfield.unique and len(rtable._primarykey)1:


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Reference field to string field in a keyed table. MSSQL

2013-02-28 Thread DenesL
Keyed tables can only reference (or be referenced by) other keyed tables.

See 
http://web2py.com/books/default/chapter/29/06#Legacy-databases-and-keyed-tables


On Thursday, February 28, 2013 8:29:32 AM UTC-5, Dmitry Mosin wrote:

 type 'exceptions.TypeError'(argument of type 'bool' is not iterable)

 *File /var/www/py/web2py/gluon/dal.py in create_table at line 772* 
  Function argument list 

 (self=gluon.dal.MSSQLAdapter object, table=Table m_dsc_clients (...), 
 migrate=True, fake_migrate=False, polymodel=None)
  Code listing 


 if hasattr(table,'_primarykey'):
 rtablename,rfieldname = referenced.split('.')
 rtable = db[rtablename]
 rfield = rtable[rfieldname]
 # must be PK reference or unique
 if rfieldname in hasattr(rtable,'_primarykey') \
 or rfield.unique:

 ftype = types[rfield.type[:9]] % \
 dict(length=rfield.length)
 # multicolumn primary key reference?
 if not rfield.unique and 
 len(rtable._primarykey)1:




-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Reference field to string field in a keyed table. MSSQL

2013-02-28 Thread Dmitry Mosin


 eyed tables can only reference (or be referenced by) other keyed tables.


But this table is keyed, isn't it?

db.define_table('m_dsc_
clients',
Field('cn','string'),
Field('cardid','reference m_dsc_cards'),
primarykey=['cn'],
)


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Reference field to string field in a keyed table. MSSQL

2013-02-27 Thread DenesL
Hi Dmitry,

option 3 is the closest one since references between keyed tables *must* 
use tablename.fieldname,

but migrate=False should be added to each table unless it is specified in 
the DB definition.

Please try again and let us know.

Regards,
Denes


On Wednesday, February 27, 2013 9:39:07 AM UTC-5, Dmitry Mosin wrote:

 Hello friends


 There are a couple of legacy tables.
 I try to create a reference between them.

 = 1 == 
 db.define_table('m_dsc_cards',
 Field('cardid','string',notnull=True,unique=True),
 primarykey=['cardid'],
 )

 db.define_table('m_dsc_clients',
 Field('cn','string'),
 Field('cardid','reference m_dsc_cards'),
 )

 class 'pyodbc.ProgrammingError' ('42000', [42000] [FreeTDS][SQL 
 Server]Column 'm_dsc_cards.cardid' is not the same data type as referencing 
 column 'm_dsc_clients.cardid' in foreign key 
 'm_dsc_clients_cardid__constraint'. (1778) (SQLExecDirectW))



 = 2 ==
 db.define_table('m_dsc_cards',
 Field('cardid','string',notnull=True,unique=True),
 primarykey=['cardid'],
 )

 db.define_table('m_dsc_clients',
 Field('cn','string'),
 Field('cardid','reference m_dsc_cards.cardid'),
 )

 class 'pyodbc.ProgrammingError' ('42000', [42000] [FreeTDS][SQL 
 Server]Foreign key 'm_dsc_clients_cardid__constraint' references invalid 
 table 'm_dsc_cards.cardid'. (1767) (SQLExecDirectW))



 = 3 ==
 db.define_table('m_dsc_cards',
 Field('cardid','string',notnull=True,unique=True),
 primarykey=['cardid'],
 )

 db.define_table('m_dsc_clients',
 Field('cn','string'),
 Field('cardid','reference m_dsc_cards.cardid'),
 primarykey=['cn'],
 )

 type 'exceptions.TypeError' argument of type 'bool' is not iterable


 = 4 == 
 db.define_table('m_dsc_cards',
 Field('cardid','string',notnull=True,unique=True),
 primarykey=['cardid'],
 )

 db.define_table('m_dsc_clients',
 Field('cn','string'),
 Field('cardid','reference m_dsc_cards'),
 primarykey=['cn'],
 )

 Wow! no exception!
 But... field has created with wrong type, INT instead of VARCHAR :(




-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.