Hi Oleg,

Thanks for this, but I'm still slightly confused.

My column names don't (I don't think - I can't tell) follow one of the standard styles.  Do I need to create them all manually like:

BOB = StringCol(dbName="BOB")

or can I use the columns (or columnsList?) dictionary? If I can use columns, how do I actually initialise / fill the dictionary?


2009/9/29 Oleg Broytman <phd@phd.pp.ru>
On Tue, Sep 29, 2009 at 09:03:51AM +0100, Chris Wood wrote:
> I'm new to using SQLObject,


> and having some problems with getting it
> to recognise my current MySQL database.

  Making SQLObject to work with existing databases could be problematic,
sometimes even impossible; let's hope it's not your case.

> class Table1(sqlobject.SQLObject):
>  _connection = conn
>  _fromDatabase = True
>  class sqlmeta:
>     table = 'Table1'
>     idName = 'Table1ID'
>  BOB = StringCol()

  You don't need both _fromDatabase and columns. Either you use
_fromDatabase and allow SQLObject to get the list of columns from the
backend, or you declare your columns yourself.

> I've seen the attribute in class sqlmeta of 'columns' - will this find
> my column names automatically,

  Yes, if _fromDatabase = True.

> or do I still need to input them
> manually? If the latter..:

  Yes, if _fromDatabase = False.

> I assume I set the names of each column in the instance of sqlmeta
> (like I have done with the table name) - how do I do this?! Do I do
> this before or after I've told SQLObject that the BOB column is a
> String column?

  SQLObject processes your class declaration as a whole so it doesn't
matter (if I understand your question correctly).

class Table1(sqlobject.SQLObject):
 _connection = conn

 class sqlmeta:
   table = 'Table1'
   idName = 'Table1ID'

 BOB = StringCol()

  is the same as

class Table1(sqlobject.SQLObject):
 class sqlmeta:
   table = 'Table1'
   idName = 'Table1ID'

 _connection = conn
 BOB = StringCol()

  is the same as

class Table1(sqlobject.SQLObject):
 _connection = conn
 BOB = StringCol()

 class sqlmeta:
   table = 'Table1'
   idName = 'Table1ID'

  (See - I didn't use _fromDatabase and SQLObject assumes it's False and
expects you to provide a list of columns)

> Is there a published list of the default naming convention that
> SQLObject follows? I couldn't find it on the website.

  SQLObject uses "style" to convert names between Python and backend. See
styles.py for existing styles. Default style is MixedCaseUnderscoreStyle but
you can change it for a class (table), a group of classes or the entire
  If you don't want to override the entire style but only want to change a
few names (of if your existing DB doesn't follow any style at all) - you
can set the names for the table and the columns:

class Table1(sqlobject.SQLObject):
 class sqlmeta:
   table = 'Table1'
   idName = 'Table1ID'

 _connection = conn
 BOB = StringCol(dbName='strbob')

    Oleg Broytman            http://phd.pp.ru/            phd@phd.pp.ru
          Programmers don't die, they just GOSUB without RETURN.

Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
sqlobject-discuss mailing list