Jeremy Hoyle | 26 Mar 2012 01:56
Picon

SqlObject Sqlmeta fromDatabase problem

I have a problem while trying to use the "fromDatabase = True" option in sqlmeta. Any time I enable this. it gives me the connection error below. Is there another attribute I need to do before doing this? I saw another thread with this problem but the solution was enable the connection before the class which I have done.

from sqlobject import *

class Companys(SQLObject):
     def __init__(self):
        connection_string = 'mysql://user:password <at> 127.0.0.1:3306/pySMS'
        conn = connectionForURI(connection_string,debug = True,autoCommit = True)
        trans = conn.transaction()
        sqlhub.processConnection = conn
        Company.createTable(ifNotExists = True, connection=conn)
        Company._connection.debug = True
    
class Company(SQLObject):

    class sqlmeta:
       fromDatabase = True
       lazyUpdate = True
       cacheValues = True
 
    Company_Name = StringCol(length = 256, default = None)
    Company_Address = StringCol(length = 256, default = None)
    Company_Phone = StringCol(length = 256, default = None)

Traceback (most recent call last):
  File "C:\Pysoft\Software\SMS Development\tests\test0.py", line 5, in <module>
    from pySMS import Companys
  File "C:\Pysoft\Software\SMS Development\pySMS\__init__.py", line 1, in <module>
    from Company import Companys
  File "C:\Pysoft\Software\SMS Development\pySMS\Company.py", line 138, in <module>
    class Company(SQLObject):
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\declarative.py", line 92, in __new__
    cls.__classinit__(cls, new_attrs)
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py", line 789, in __classinit__
    sqlmeta.addColumnsFromDatabase()
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py", line 441, in addColumnsFromDatabase
    conn = connection or soClass._connection
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py", line 902, in __get__
    return self.getConnection()
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py", line 915, in getConnection
    "No connection has been defined for this thread "
AttributeError: No connection has been defined for this thread or process

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 26 Mar 2012 10:52
X-Face
Favicon
Gravatar

Re: SqlObject Sqlmeta fromDatabase problem

Hi!

On Sun, Mar 25, 2012 at 06:56:32PM -0500, Jeremy Hoyle wrote:
> I have a problem while trying to use the "fromDatabase = True" option in
> sqlmeta. Any time I enable this. it gives me the connection error below. Is
> there another attribute I need to do before doing this? I saw another
> thread with this problem but the solution was enable the connection before
> the class which I have done.
> 
> from sqlobject import *
> 
> class Companys(SQLObject):
>      def __init__(self):
>         connection_string = 'mysql://user:password <at> 127.0.0.1:3306/pySMS'
>         conn = connectionForURI(connection_string,debug = True,autoCommit =
> True)
>         trans = conn.transaction()
>         sqlhub.processConnection = conn
>         Company.createTable(ifNotExists = True, connection=conn)
>         Company._connection.debug = True

   A number of problems here.
1. The connection is created in Companys.__init__ which is not called,
at least it is not called when SQLObject's metaclass processes
fromDatabase. fromDatabase requires an open connection.
2. A transaction is opened but never used. Transaction (trans, in your
case) has to be used instead of connection (in sqlhub, or in every
SQLObject call that accepts connection).

> class Company(SQLObject):
> 
>     class sqlmeta:
>        fromDatabase = True
>        lazyUpdate = True
>        cacheValues = True
> 
>     Company_Name = StringCol(length = 256, default = None)
>     Company_Address = StringCol(length = 256, default = None)
>     Company_Phone = StringCol(length = 256, default = None)
> 
> Traceback (most recent call last):
>   File "C:\Pysoft\Software\SMS Development\tests\test0.py", line 5, in
> <module>
>     from pySMS import Companys
>   File "C:\Pysoft\Software\SMS Development\pySMS\__init__.py", line 1, in
> <module>
>     from Company import Companys
>   File "C:\Pysoft\Software\SMS Development\pySMS\Company.py", line 138, in
> <module>
>     class Company(SQLObject):
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\declarative.py",
> line 92, in __new__
>     cls.__classinit__(cls, new_attrs)
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py",
> line 789, in __classinit__
>     sqlmeta.addColumnsFromDatabase()
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py",
> line 441, in addColumnsFromDatabase
>     conn = connection or soClass._connection
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py",
> line 902, in __get__
>     return self.getConnection()
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py",
> line 915, in getConnection
>     "No connection has been defined for this thread "
> AttributeError: No connection has been defined for this thread or process

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
Jeremy Hoyle | 26 Mar 2012 11:30
Picon

Re: SqlObject Sqlmeta fromDatabase problem

Thank you for your response. I'm sorry for not including these details for I have been struggling with this problem for sometime. These suggestions have been tried or already implemented with the same result. Pleased let me know if you have any other suggestions.


def __init__(self):
    connection_string = 'mysql://user:password <at> 127.0.0.1:3306/pySMS'
    conn = connectionForURI(connection_string,debug = True,autoCommit = True)
    trans = conn.transaction()
    sqlhub.processConnection = conn
    Company.createTable(ifNotExists = True, connection=trans)

test0.py file

import sys
from sqlobject import *
from pySMS import Companys

if __name__ == "__main__":

    pysoft = Companys()


Traceback (most recent call last):
  File "C:\Pysoft\Software\SMS Development\tests\test0.py", line 5, in <module>
    from pySMS import Companys
  File "C:\Pysoft\Software\SMS Development\pySMS\__init__.py", line 1, in <module>
    from Company import Companys
  File "C:\Pysoft\Software\SMS Development\pySMS\Company.py", line 137, in <module>
    class Company(SQLObject):
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\declarative.py", line 92, in __new__
    cls.__classinit__(cls, new_attrs)
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py", line 789, in __classinit__
    sqlmeta.addColumnsFromDatabase()
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py", line 441, in addColumnsFromDatabase
    conn = connection or soClass._connection
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py", line 902, in __get__
    return self.getConnection()
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py", line 915, in getConnection
    "No connection has been defined for this thread "
AttributeError: No connection has been defined for this thread or process



On Mon, Mar 26, 2012 at 3:52 AM, Oleg Broytman <phd <at> phdru.name> wrote:
Hi!

On Sun, Mar 25, 2012 at 06:56:32PM -0500, Jeremy Hoyle wrote:
> I have a problem while trying to use the "fromDatabase = True" option in
> sqlmeta. Any time I enable this. it gives me the connection error below. Is
> there another attribute I need to do before doing this? I saw another
> thread with this problem but the solution was enable the connection before
> the class which I have done.
>
> from sqlobject import *
>
> class Companys(SQLObject):
>      def __init__(self):
>         connection_string = 'mysql://user:password <at> 127.0.0.1:3306/pySMS'
>         conn = connectionForURI(connection_string,debug = True,autoCommit =
> True)
>         trans = conn.transaction()
>         sqlhub.processConnection = conn
>         Company.createTable(ifNotExists = True, connection=conn)
>         Company._connection.debug = True

  A number of problems here.
1. The connection is created in Companys.__init__ which is not called,
at least it is not called when SQLObject's metaclass processes
fromDatabase. fromDatabase requires an open connection.
2. A transaction is opened but never used. Transaction (trans, in your
case) has to be used instead of connection (in sqlhub, or in every
SQLObject call that accepts connection).

> class Company(SQLObject):
>
>     class sqlmeta:
>        fromDatabase = True
>        lazyUpdate = True
>        cacheValues = True
>
>     Company_Name = StringCol(length = 256, default = None)
>     Company_Address = StringCol(length = 256, default = None)
>     Company_Phone = StringCol(length = 256, default = None)
>
> Traceback (most recent call last):
>   File "C:\Pysoft\Software\SMS Development\tests\test0.py", line 5, in
> <module>
>     from pySMS import Companys
>   File "C:\Pysoft\Software\SMS Development\pySMS\__init__.py", line 1, in
> <module>
>     from Company import Companys
>   File "C:\Pysoft\Software\SMS Development\pySMS\Company.py", line 138, in
> <module>
>     class Company(SQLObject):
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\declarative.py",
> line 92, in __new__
>     cls.__classinit__(cls, new_attrs)
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py",
> line 789, in __classinit__
>     sqlmeta.addColumnsFromDatabase()
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py",
> line 441, in addColumnsFromDatabase
>     conn = connection or soClass._connection
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py",
> line 902, in __get__
>     return self.getConnection()
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py",
> line 915, in getConnection
>     "No connection has been defined for this thread "
> AttributeError: No connection has been defined for this thread or process

Oleg.
--
    Oleg Broytman            http://phdru.name/            phd <at> phdru.name
          Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 26 Mar 2012 11:42
X-Face
Favicon
Gravatar

Re: SqlObject Sqlmeta fromDatabase problem

On Mon, Mar 26, 2012 at 04:30:26AM -0500, Jeremy Hoyle wrote:
> Thank you for your response. I'm sorry for not including these details for
> I have been struggling with this problem for sometime. These suggestions
> have been tried or already implemented with the same result. Pleased let me
> know if you have any other suggestions.
> 
> def __init__(self):
>     connection_string = 'mysql://user:password <at> 127.0.0.1:3306/pySMS'
>     conn = connectionForURI(connection_string,debug = True,autoCommit =
> True)
>     trans = conn.transaction()
>     sqlhub.processConnection = conn
>     Company.createTable(ifNotExists = True, connection=trans)

   What's that? A global function or a method? Where it's called?

> test0.py file
> 
> import sys
> from sqlobject import *
> from pySMS import Companys
> 
> if __name__ == "__main__":
> 
>     pysoft = Companys()
> 
> 
> Traceback (most recent call last):
>   File "C:\Pysoft\Software\SMS Development\tests\test0.py", line 5, in
> <module>
>     from pySMS import Companys
>   File "C:\Pysoft\Software\SMS Development\pySMS\__init__.py", line 1, in
> <module>
>     from Company import Companys
>   File "C:\Pysoft\Software\SMS Development\pySMS\Company.py", line 137, in
> <module>
>     class Company(SQLObject):
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\declarative.py",
> line 92, in __new__
>     cls.__classinit__(cls, new_attrs)
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py",
> line 789, in __classinit__
>     sqlmeta.addColumnsFromDatabase()
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py",
> line 441, in addColumnsFromDatabase
>     conn = connection or soClass._connection
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py",
> line 902, in __get__
>     return self.getConnection()
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py",
> line 915, in getConnection
>     "No connection has been defined for this thread "
> AttributeError: No connection has been defined for this thread or process

   The same problem - no connection has been defined. The code tried to
open a connection in Companys.__init__, but Companys is an SQLObject's
table and thus requires an open connection.
   Open a connection outside of SQLObject's initialization.

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
Jeremy Hoyle | 26 Mar 2012 14:42
Picon

Re: SqlObject Sqlmeta fromDatabase problem

 What's that? A global function or a method? Where it's called? 

It is the Companys class. It is called from my test0.py file. See below.

 The same problem - no connection has been defined. The code tried to
open a connection in Companys.__init__, but Companys is an SQLObject's
table and thus requires an open connection.
 Open a connection outside of SQLObject's initialization.

Companys is not a sqlobject table. Company is a sqlobject table. Sorry for the confusion. I chose poor naming. Do I not need to extend the SQLObject in Companys? See all of them below.

Company.py file 
class Company(SQLObject):
    class sqlmeta:
       fromDatabase = True
       lazyUpdate = True
       cacheValues = True
   Company_Name = StringCol(length = 256, default = None)
   Company_Address = StringCol(length = 256, default = None)
   Company_Phone = StringCol(length = 256, default = None)

class Companys(SQLObject):
     def __init__(self):
         connection_string = 'mysql://user:password <at> 127.0.0.1:3306/pySMS'
         conn = connectionForURI(connection_string,debug = True,autoCommit =True)
         trans = conn.transaction()
         sqlhub.processConnection = conn
         Company.createTable(ifNotExists = True, connection=trans)

 test0.py file

 import sys
 from sqlobject import *
 from pySMS import Companys

 if __name__ == "__main__":

     pysoft = Companys()

On Mon, Mar 26, 2012 at 4:42 AM, Oleg Broytman <phd <at> phdru.name> wrote:
On Mon, Mar 26, 2012 at 04:30:26AM -0500, Jeremy Hoyle wrote:
> Thank you for your response. I'm sorry for not including these details for
> I have been struggling with this problem for sometime. These suggestions
> have been tried or already implemented with the same result. Pleased let me
> know if you have any other suggestions.
>
> def __init__(self):
>     connection_string = 'mysql://user:password <at> 127.0.0.1:3306/pySMS'
>     conn = connectionForURI(connection_string,debug = True,autoCommit =
> True)
>     trans = conn.transaction()
>     sqlhub.processConnection = conn
>     Company.createTable(ifNotExists = True, connection=trans)

  What's that? A global function or a method? Where it's called?

> test0.py file
>
> import sys
> from sqlobject import *
> from pySMS import Companys
>
> if __name__ == "__main__":
>
>     pysoft = Companys()
>
>
> Traceback (most recent call last):
>   File "C:\Pysoft\Software\SMS Development\tests\test0.py", line 5, in
> <module>
>     from pySMS import Companys
>   File "C:\Pysoft\Software\SMS Development\pySMS\__init__.py", line 1, in
> <module>
>     from Company import Companys
>   File "C:\Pysoft\Software\SMS Development\pySMS\Company.py", line 137, in
> <module>
>     class Company(SQLObject):
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\declarative.py",
> line 92, in __new__
>     cls.__classinit__(cls, new_attrs)
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py",
> line 789, in __classinit__
>     sqlmeta.addColumnsFromDatabase()
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py",
> line 441, in addColumnsFromDatabase
>     conn = connection or soClass._connection
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py",
> line 902, in __get__
>     return self.getConnection()
>   File
> "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py",
> line 915, in getConnection
>     "No connection has been defined for this thread "
> AttributeError: No connection has been defined for this thread or process

  The same problem - no connection has been defined. The code tried to
open a connection in Companys.__init__, but Companys is an SQLObject's
table and thus requires an open connection.
  Open a connection outside of SQLObject's initialization.

Oleg.
--
    Oleg Broytman            http://phdru.name/            phd <at> phdru.name
          Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 26 Mar 2012 14:47
X-Face
Favicon
Gravatar

Re: SqlObject Sqlmeta fromDatabase problem

On Mon, Mar 26, 2012 at 07:42:40AM -0500, Jeremy Hoyle wrote:
> *Companys is not a sqlobject table. Company is a sqlobject table.
> 
> class Companys(SQLObject):

   I clearly see here that Companys is an SQLObject and hence require a
connection.

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
Jeremy Hoyle | 26 Mar 2012 14:59
Picon

Re: SqlObject Sqlmeta fromDatabase problem

Yes. If I remove Companys as a SQLObject.I still receive the same error. I'm not sure from the sequence of the ( from Company import Companys ) is trying to initiate (  class Company(SQLObject) ) class.


class Companys():
    def __init__(self):
       connection_string = 'mysql://root:ttlan1 <at> 127.0.0.1:3306/pySMS'
       conn = connectionForURI(connection_string,debug = True,autoCommit = True)
       trans = conn.transaction()
       sqlhub.processConnection = conn
       Company.createTable(ifNotExists = True, connection=trans)

Traceback (most recent call last):
  File "C:\Pysoft\Software\SMS Development\tests\test0.py", line 5, in <module>
    from pySMS import Companys
  File "C:\Pysoft\Software\SMS Development\pySMS\__init__.py", line 1, in <module>
    from Company import Companys
  File "C:\Pysoft\Software\SMS Development\pySMS\Company.py", line 137, in <module>
    class Company(SQLObject):
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\declarative.py", line 92, in __new__
    cls.__classinit__(cls, new_attrs)
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py", line 789, in __classinit__
    sqlmeta.addColumnsFromDatabase()
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\main.py", line 441, in addColumnsFromDatabase
    conn = connection or soClass._connection
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py", line 902, in __get__
    return self.getConnection()
  File "C:\Python27\lib\site-packages\sqlobject-1.2.1-py2.7.egg\sqlobject\dbconnection.py", line 915, in getConnection
    "No connection has been defined for this thread "
AttributeError: No connection has been defined for this thread or process

On Mon, Mar 26, 2012 at 7:47 AM, Oleg Broytman <phd <at> phdru.name> wrote:
On Mon, Mar 26, 2012 at 07:42:40AM -0500, Jeremy Hoyle wrote:
> *Companys is not a sqlobject table. Company is a sqlobject table.
>
> class Companys(SQLObject):

  I clearly see here that Companys is an SQLObject and hence require a
connection.

Oleg.
--
    Oleg Broytman            http://phdru.name/            phd <at> phdru.name
          Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 26 Mar 2012 15:05
X-Face
Favicon
Gravatar

Re: SqlObject Sqlmeta fromDatabase problem

On Mon, Mar 26, 2012 at 07:59:39AM -0500, Jeremy Hoyle wrote:
>   File "C:\Pysoft\Software\SMS Development\tests\test0.py", line 5, in
> <module>
>     from pySMS import Companys
>   File "C:\Pysoft\Software\SMS Development\pySMS\__init__.py", line 1, in
> <module>
>     from Company import Companys

   Here is the problem now - Company (and Companys) is imported before
a connection is created. You have to open a connection before the class
Company is created (i.e., before the module is imported).

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
Jeremy Hoyle | 26 Mar 2012 15:16
Picon

Re: SqlObject Sqlmeta fromDatabase problem

Ok. I got it. I just defined the connection above and outside the Companys and Company classes. Thanks for your help.


Jeremy

On Mon, Mar 26, 2012 at 8:05 AM, Oleg Broytman <phd <at> phdru.name> wrote:
On Mon, Mar 26, 2012 at 07:59:39AM -0500, Jeremy Hoyle wrote:
>   File "C:\Pysoft\Software\SMS Development\tests\test0.py", line 5, in
> <module>
>     from pySMS import Companys
>   File "C:\Pysoft\Software\SMS Development\pySMS\__init__.py", line 1, in
> <module>
>     from Company import Companys

  Here is the problem now - Company (and Companys) is imported before
a connection is created. You have to open a connection before the class
Company is created (i.e., before the module is imported).

Oleg.
--
    Oleg Broytman            http://phdru.name/            phd <at> phdru.name
          Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Jeremy Hoyle | 27 Mar 2012 02:55
Picon

Re: SqlObject Sqlmeta fromDatabase problem

Thank you for your help but although I am not receiving any errors. The  fromDatabase boolean doesn't seem to be performing its stated function.


fromDatabase: A boolean (default false). If true, then on class creation the database will be queried for the table's columns, and any missing columns (possible all columns) will be added automatically.
I started with these
class Company(SQLObject):
class sqlmeta:
        fromDatabase = True
        lazyUpdate = False
        cacheValues = True
    Company_Name = StringCol(length = 256, default = None)
    Company_Address = StringCol(length = 256, default = None)
    Company_Phone = StringCol(length = 256, default = None)

Added 
class Company(SQLObject):
class sqlmeta:
        fromDatabase = True
        lazyUpdate = False
        cacheValues = True
    Company_Name = StringCol(length = 256, default = None)
    Company_Address = StringCol(length = 256, default = None)
    Company_Phone = StringCol(length = 256, default = None)
 Company_Phone = StringCol(length = 256, default = None)
On Mon, Mar 26, 2012 at 8:16 AM, Jeremy Hoyle <jeremiah.r.hoyle <at> gmail.com> wrote:
Ok. I got it. I just defined the connection above and outside the Companys and Company classes. Thanks for your help.

Jeremy


On Mon, Mar 26, 2012 at 8:05 AM, Oleg Broytman <phd <at> phdru.name> wrote:
On Mon, Mar 26, 2012 at 07:59:39AM -0500, Jeremy Hoyle wrote:
>   File "C:\Pysoft\Software\SMS Development\tests\test0.py", line 5, in
> <module>
>     from pySMS import Companys
>   File "C:\Pysoft\Software\SMS Development\pySMS\__init__.py", line 1, in
> <module>
>     from Company import Companys

  Here is the problem now - Company (and Companys) is imported before
a connection is created. You have to open a connection before the class
Company is created (i.e., before the module is imported).

Oleg.
--
    Oleg Broytman            http://phdru.name/            phd <at> phdru.name
          Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss


------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Jeremy Hoyle | 27 Mar 2012 03:02
Picon

Re: SqlObject Sqlmeta fromDatabase problem

Sorry.. the previous post was in error.

Thank you for your help but although I am not receiving any errors. The  fromDatabase boolean doesn't seem to be performing its stated function.It does not update the database when i enter a new column in the database.

fromDatabase: A boolean (default false). If true, then on class creation the database will be queried for the table's columns, and any missing columns (possible all columns) will be added automatically.
I started with these
class Company(SQLObject):
class sqlmeta:
        fromDatabase = True
        lazyUpdate = False
        cacheValues = True
    Company_Name = StringCol(length = 256, default = None)
    Company_Address = StringCol(length = 256, default = None)
    Company_Phone = StringCol(length = 256, default = None)

Added 
class Company(SQLObject):
class sqlmeta:
        fromDatabase = True
        lazyUpdate = False
        cacheValues = True
    Company_Name = StringCol(length = 256, default = None)
    Company_Address = StringCol(length = 256, default = None)
    Company_Phone = StringCol(length = 256, default = None)
    Company_Number = StringCol(length = 256, default = None)

class Companys():
    def __init__(self):
         Company.createTable(ifNotExists = True, connection=conn)

Output:>> 
 2/QueryAll:  SHOW COLUMNS FROM store
 2/QueryAll:  SHOW COLUMNS FROM company
 2/Query   :  DESCRIBE company
 2/Query   :  DESCRIBE store

On Mon, Mar 26, 2012 at 7:55 PM, Jeremy Hoyle <jeremiah.r.hoyle <at> gmail.com> wrote:
Thank you for your help but although I am not receiving any errors. The  fromDatabase boolean doesn't seem to be performing its stated function.

fromDatabase: A boolean (default false). If true, then on class creation the database will be queried for the table's columns, and any missing columns (possible all columns) will be added automatically.
I started with these
class Company(SQLObject):
class sqlmeta:
        fromDatabase = True
        lazyUpdate = False
        cacheValues = True
    Company_Name = StringCol(length = 256, default = None)
    Company_Address = StringCol(length = 256, default = None)
    Company_Phone = StringCol(length = 256, default = None)

Added 
class Company(SQLObject):
class sqlmeta:
        fromDatabase = True
        lazyUpdate = False
        cacheValues = True
    Company_Name = StringCol(length = 256, default = None)
    Company_Address = StringCol(length = 256, default = None)
    Company_Phone = StringCol(length = 256, default = None)
 Company_Phone = StringCol(length = 256, default = None)
On Mon, Mar 26, 2012 at 8:16 AM, Jeremy Hoyle <jeremiah.r.hoyle <at> gmail.com> wrote:
Ok. I got it. I just defined the connection above and outside the Companys and Company classes. Thanks for your help.

Jeremy


On Mon, Mar 26, 2012 at 8:05 AM, Oleg Broytman <phd <at> phdru.name> wrote:
On Mon, Mar 26, 2012 at 07:59:39AM -0500, Jeremy Hoyle wrote:
>   File "C:\Pysoft\Software\SMS Development\tests\test0.py", line 5, in
> <module>
>     from pySMS import Companys
>   File "C:\Pysoft\Software\SMS Development\pySMS\__init__.py", line 1, in
> <module>
>     from Company import Companys

  Here is the problem now - Company (and Companys) is imported before
a connection is created. You have to open a connection before the class
Company is created (i.e., before the module is imported).

Oleg.
--
    Oleg Broytman            http://phdru.name/            phd <at> phdru.name
          Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss



------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Petr Jakeš | 27 Mar 2012 09:13
Picon

Re: SqlObject Sqlmeta fromDatabase problem




fromDatabase: A boolean (default false). If true, then on class creation the database will be queried for the table's columns, and any missing columns (possible all columns) will be added automatically.
I started with these
class Company(SQLObject):
class sqlmeta:
        fromDatabase = True
        lazyUpdate = False
        cacheValues = True
    Company_Name = StringCol(length = 256, default = None)
    Company_Address = StringCol(length = 256, default = None)
    Company_Phone = StringCol(length = 256, default = None)

Added 
class Company(SQLObject):
class sqlmeta:
        fromDatabase = True
        lazyUpdate = False
        cacheValues = True
    Company_Name = StringCol(length = 256, default = None)
    Company_Address = StringCol(length = 256, default = None)
    Company_Phone = StringCol(length = 256, default = None)
    Company_Number = StringCol(length = 256, default = None)

class Companys():
    def __init__(self):
         Company.createTable(ifNotExists = True, connection=conn)



Hi Jeremy,
what about the Naming Style?
see: Changing the Naming Style
.... By default names in SQLObject are expected to be mixed case in Python (like mixedCase), and underscore-separated in SQL (like mixed_case). This applies to table and column names.

Regards

Petr
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 27 Mar 2012 11:43
X-Face
Favicon
Gravatar

Re: SqlObject Sqlmeta fromDatabase problem

On Mon, Mar 26, 2012 at 08:02:22PM -0500, Jeremy Hoyle wrote:
>  fromDatabase boolean doesn't seem to be performing its stated function.It
> does not update the database when i enter a new column in the database.

   I have problems understanding the sentence. Did you add a column to
your database and then restarted the program? The program didn't
discover the new column? You can test the list of columns by printing
Company.sqlmeta.columnList and Company.sqlmeta.columns.

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
Jeremy Hoyle | 27 Mar 2012 12:27
Picon

Re: SqlObject Sqlmeta fromDatabase problem

I added a stringcol to the class Company(SQLObject) table but it did not auto update my database with the column. I am not sure why it is not updating. I check my SQL database with an external GUI. The database views below should be updated automatically when adding a new StringCol entry in the Company table. Correct?


BEFORE:
class Company(SQLObject):
class sqlmeta:
        fromDatabase = True
        lazyUpdate = False
        cacheValues = True
    Company_Name = StringCol(length = 256, default = None)
    Company_Address = StringCol(length = 256, default = None)
    Company_Phone = StringCol(length = 256, default = None)



AFTER:
class Company(SQLObject):
class sqlmeta:
        fromDatabase = True
        lazyUpdate = False
        cacheValues = True
    Company_Name = StringCol(length = 256, default = None)
    Company_Address = StringCol(length = 256, default = None)
    Company_Phone = StringCol(length = 256, default = None)
    Company_Number = StringCol(length = 256, default = None)


class Companys():
    def __init__(self):
         Company.createTable(ifNotExists = True, connection=conn)


On Tue, Mar 27, 2012 at 4:43 AM, Oleg Broytman <phd <at> phdru.name> wrote:
On Mon, Mar 26, 2012 at 08:02:22PM -0500, Jeremy Hoyle wrote:
>  fromDatabase boolean doesn't seem to be performing its stated function.It
> does not update the database when i enter a new column in the database.

  I have problems understanding the sentence. Did you add a column to
your database and then restarted the program? The program didn't
discover the new column? You can test the list of columns by printing
Company.sqlmeta.columnList and Company.sqlmeta.columns.

Oleg.
--
    Oleg Broytman            http://phdru.name/            phd <at> phdru.name
          Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 27 Mar 2012 12:32
X-Face
Favicon
Gravatar

Re: SqlObject Sqlmeta fromDatabase problem

On Tue, Mar 27, 2012 at 05:27:45AM -0500, Jeremy Hoyle wrote:
> I added a stringcol to the class Company(SQLObject) table but it did not
> auto update my database with the column.

   You've got it in the reverse direction. fromDatase gets the list of
columns *from* database. If you want to add a column from python to
database you ought to use sqlmeta.addColumn() with changeSchema set to
True.

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
Jeremy Hoyle | 27 Mar 2012 12:43
Picon

Re: SqlObject Sqlmeta fromDatabase problem

Ok.. thank you. I was under the impression that this function will add an column automatically to my database after I included it in my class. I might code this functionality into sqlmeta. I would find this to be very useful for future changes.


Jeremy

On Tue, Mar 27, 2012 at 5:32 AM, Oleg Broytman <phd <at> phdru.name> wrote:
On Tue, Mar 27, 2012 at 05:27:45AM -0500, Jeremy Hoyle wrote:
> I added a stringcol to the class Company(SQLObject) table but it did not
> auto update my database with the column.

  You've got it in the reverse direction. fromDatase gets the list of
columns *from* database. If you want to add a column from python to
database you ought to use sqlmeta.addColumn() with changeSchema set to
True.

Oleg.
--
    Oleg Broytman            http://phdru.name/            phd <at> phdru.name
          Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Gmane