Sorry the delay... :-P

I have translate all to portuguese so the class and the tables don't conflit with SQLObject or mysql but gives me an error.

I'm using SQLObject-0.8dev_r1335-py2.4.egg

Below is the script and the error:



from sqlobject import *
conn_str = "mysql://sharky:passwd@localhost/testes?debug=t"
sqlhub.processConnection = connectionForURI(conn_str)

class GruposUtilizadores(SQLObject):
    class sqlmeta:
        table = 'grupos_utilizadores'
    grupo = ForeignKey('Grupo', notNull=True)
    utilizador = ForeignKey('Utilizador', notNull=True)
    unique = index.DatabaseIndex(grupo, utilizador, unique=True)

class Utilizador(SQLObject):
    alcunha = StringCol(alternateID=True, unique=True, length=20)
    nome = StringCol(alternateID=True, unique=True, length=100)
    senha = StringCol(length=32)
    grupos = RelatedJoin('Grupo', createRelatedTable=False)

class Grupo(SQLObject):
    nome = StringCol(alternateID=True, length=15)
    descr = StringCol(length=100)
    utilizadores = RelatedJoin('Utilizador', createRelatedTable=False)

GruposUtilizadores.createTable()
Utilizador.createTable()
Groupo.createTable()



Traceback (most recent call last):
  File "teste_mail1.py", line 25, in ?
    GruposUtilizadores.createTable()
  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/main.py", line 1392, in createTable
    constraints = conn.createTable(cls)
  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/dbconnection.py", line 531, in createTable
    createSql, constraints = self.createTableSQL(soClass)
  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/dbconnection.py", line 563, in createTableSQL
    constraints = self.createReferenceConstraints(soClass)
  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/dbconnection.py", line 537, in createReferenceConstraints
    refConstraints = [self.createReferenceConstraint(soClass, column) \
  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/dbconnection.py", line 576, in createReferenceConstraint
    assert 0, "Implement in subclasses"
AssertionError: Implement in subclasses





2005/12/5, Rick Flosi <rflosi@imagescape.com>:
Can you create the group table by itself?
Maybe group is a keyword in MySQL. user may be as well. You might have to
set alternate table names like user_info and group_info for those tables.

You can do that using sqlmeta.table like in GroupUser.

--
Rick

On Mon, 5 Dec 2005, Helio MC Pereira wrote:

> I have add ?debut=t in the connection URI and it gaves me this sql
> with the error I mantioned before:
>
> 1/Query   :  CREATE TABLE user (
>    id INT PRIMARY KEY AUTO_INCREMENT,
>    nickname VARCHAR(20) NOT NULL UNIQUE,
>    name VARCHAR(100) NOT NULL UNIQUE,
>    passwd VARCHAR(32)
> )
> 1/Query   :  CREATE TABLE group (
>    id INT PRIMARY KEY AUTO_INCREMENT,
>    name VARCHAR(15) NOT NULL UNIQUE,
>    descr VARCHAR(100)
> )
>
>
> So I decided to change de python code an create the GroupUser class
> first from the others and create the table first to. It gives me this
> error:
>
> Traceback (most recent call last):
>  File "teste_mail1.py", line 25, in ?
>    GroupUser.createTable ()
>  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/main.py",
> line 1392, in createTable
>    constraints = conn.createTable(cls)
>  File "/usr/lib/python2.4/site-packages/SQLObject- 0.8dev_r1335-py2.4.egg/sqlobject/dbconnection.py",
> line 531, in createTable
>    createSql, constraints = self.createTableSQL(soClass)
>  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/dbconnection.py ",
> line 563, in createTableSQL
>    constraints = self.createReferenceConstraints(soClass)
>  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/dbconnection.py ",
> line 537, in createReferenceConstraints
>    refConstraints = [self.createReferenceConstraint(soClass, column) \
>  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/dbconnection.py ",
> line 576, in createReferenceConstraint
>    assert 0, "Implement in subclasses"
> AssertionError: Implement in subclasses
>
>
> I put here the python code:
>
> from sqlobject import *
> conn_str = "mysql://sharky:jonas@localhost/testes?debug=t"
> sqlhub.processConnection = connectionForURI(conn_str)
>
> class GroupUser(SQLObject):
>    class sqlmeta:
>        table = 'group_user'
>    group = ForeignKey('Group', notNull=True)
>    user = ForeignKey('User', notNull=True)
>    unique = index.DatabaseIndex(group, user, unique=True)
>
> class User(SQLObject):
>    nickname = StringCol(alternateID=True, unique=True, length=20)
>    name = StringCol(alternateID=True, unique=True, length=100)
>    passwd = StringCol(length=32)
>    groups = RelatedJoin('Group', createRelatedTable=False)
>
> class Group(SQLObject):
>    name = StringCol(alternateID=True, length=15)
>    descr = StringCol(length=100)
>    users = RelatedJoin('User', createRelatedTable=False)
>
> GroupUser.createTable()
> User.createTable()
> Group.createTable()
>
>
>
>
> 2005/12/5, Rick Flosi < rflosi@imagescape.com>:
>> What is the full SQL it is trying to use?
>>
>> Have you tried using 'sqlobject-admin sql' to see the sql it is trying to
>> use?
>>
>> On Mon, 5 Dec 2005, Helio MC Pereira wrote:
>>
>>> that raise me an error in sql syntax...
>>>
>>>
>>> Traceback (most recent call last):
>>>  File "teste_mail1.py", line 26, in ?
>>>    Group.createTable()
>>>  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/main.py",
>>> line 1392, in createTable
>>>    constraints = conn.createTable(cls)
>>>  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/dbconnection.py",
>>> line 532, in createTable
>>>    self.query(createSql)
>>>  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/dbconnection.py",
>>> line 312, in query
>>>    return self._runWithConnection(self._query, s)
>>>  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/dbconnection.py",
>>> line 226, in _runWithConnection
>>>    val = meth(conn, *args)
>>>  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/dbconnection.py",
>>> line 309, in _query
>>>    self._executeRetry(conn, conn.cursor(), s)
>>>  File "/usr/lib/python2.4/site-packages/SQLObject-0.8dev_r1335-py2.4.egg/sqlobject/mysql/mysqlconnection.py",
>>> line 60, in _executeRetry
>>>    return cursor.execute(query)
>>>  File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
>>> 137, in execute
>>>    self.errorhandler(self, exc, value)
>>>  File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line
>>> 33, in defaulterrorhandler
>>>    raise errorclass, errorvalue
>>> _mysql_exceptions.ProgrammingError: (1064, "You have an error in your
>>> SQL syntax.  Check the manual that corresponds to your MySQL server
>>> version for the right syntax to use near 'group (\n    id INT PRIMARY
>>> KEY AUTO_INCREMENT,\n    name VARCHAR")
>>>
>>>
>>> 2005/12/4, Rick Flosi < rflosi@imagescape.com>:
>>>>
>>>> I think this will work, but I didn't test it.
>>>>
>>>> I don't know what version 'createRelatedTable' is available in, but you
>>>> need that to supress creating the default join table 'group_user' and then
>>>> just define it yourself.
>>>>
>>>> ---
>>>> class User(SQLObject):
>>>>      nickname = StringCol(alternateID=True, unique=True, length=20)
>>>>      name = StringCol(alternateID=True, unique=True, length=100)
>>>>      passwd = StringCol(length=32)
>>>>      groups = RelatedJoin('Group', createRelatedTable=False)
>>>>
>>>> class Group(SQLObject):
>>>>      name = StringCol(alternateID=True, length=15)
>>>>      descr = StringCol(length=100)
>>>>      users = RelatedJoin('User', createRelatedTable=False)
>>>>
>>>> class GroupUser(SQLObject):
>>>>      class sqlmeta:
>>>>          table = 'group_user'
>>>>      group = ForeignKey('Group', notNull=True)
>>>>      user = ForeignKey('User', notNull=True)
>>>>      unique = index.DatabaseIndex(group, user, unique=True)
>>>> ---
>>>>
>>>> Sorry this took a while for me to get back to.
>>>> Hope it works for you.
>>>>
>>>> --
>>>> Rick
>>>>
>>>> On Sat, 3 Dec 2005, Helio MC Pereira wrote:
>>>>
>>>>> It will be nice if you can put an example :-P
>>>>>
>>>>> I need something like this but that don't permit duplicate groups for the users:
>>>>>
>>>>> class User(SQLObject):
>>>>>    nickname = StringCol(alternateID=True, unique=True, length=20)
>>>>>    name = StringCol(alternateID=True, unique=True, length=100)
>>>>>    passwd = StringCol(length=32)
>>>>>    groups = RelatedJoin('Group')
>>>>>
>>>>> class Group(SQLObject):
>>>>>    name = StringCol(alternateID=True, length=15)
>>>>>    descr = StringCol(length=100)
>>>>>    users = RelatedJoin('User')
>>>>>
>>>>> sharky = Utilizador(nickname="sharky",name="Helio",passwd="xxxx")
>>>>> Jonas = Utilizador(nickname="Jonas",name="Jonas",passwd="xxxx")
>>>>>
>>>>> admin = Grupo(name="Admin", descr="administrador")
>>>>> registado = Grupo(name="Registado", descr="registado")
>>>>>
>>>>> sharky.addGroup('Admin','Registado')
>>>>> Jonas.addGroup ('Registado')
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> 2005/12/3, Rick Flosi <rflosi@imagescape.com >:
>>>>>> You can define the related table yourself and tell SQLObject not to create
>>>>>> the related table. Then make thoses fields foreign keys instead of just
>>>>>> integers. Then you can add a unique index constraint on the 2 foreign key
>>>>>> ids so that attempting to add a duplicate would raise an integrity error.
>>>>>> This will enforce your data integrity, but you'll have to handle the error
>>>>>> when it is raised.
>>>>>> I don't know if the options you need are in a release or in the trunk only
>>>>>> right now. If you need more help I'll try and put together an example.
>>>>>>
>>>>>> --
>>>>>> Rick
>>>>>>
>>>>>> On Sat, 3 Dec 2005, Helio MC Pereira wrote:
>>>>>>
>>>>>>> Hi all,
>>>>>>>
>>>>>>>   I have a problem related with many-to-many relation. Have searched
>>>>>>> in this list and see that my problem is the same in this thread:
>>>>>>> http://sourceforge.net/mailarchive/forum.php?thread_id=9049958&forum_id=30269
>>>>>>>
>>>>>>> """
>>>>>>>>>> foo = User(username="foo")
>>>>>>>>>> admin = Role(name="admin")
>>>>>>>>>> foo.addRole(admin)
>>>>>>>>>> foo.roles
>>>>>>> [admin]
>>>>>>>>>> foo.addRole(admin)
>>>>>>> [admin, admin]   <----- Duplicate !!!!
>>>>>>> """
>>>>>>>
>>>>>>>   Can anyone point me to another way of doing this?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Helio Pereira
>>>>>>>
>>>>>>>
>>>>>>> -------------------------------------------------------
>>>>>>> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
>>>>>>> for problems?  Stop!  Download the new AJAX search engine that makes
>>>>>>> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
>>>>>>> http://ads.osdn.com/?ad_idv37&alloc_id865&opk
>>>>>>> _______________________________________________
>>>>>>> sqlobject-discuss mailing list
>>>>>>> sqlobject-discuss@lists.sourceforge.net
>>>>>>> https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> -------------------------------------------------------
>>>>> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
>>>>> for problems?  Stop!  Download the new AJAX search engine that makes
>>>>> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
>>>>> http://ads.osdn.com/?ad_idv37&alloc_id865&opk
>>>>> _______________________________________________
>>>>> sqlobject-discuss mailing list
>>>>> sqlobject-discuss@lists.sourceforge.net
>>>>> https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
>>>>>
>>>>>
>>>>
>>>
>>>
>>
>
>