From: Oleg B. <ph...@ph...> - 2009-09-29 10:59:15
|
On Tue, Sep 29, 2009 at 09:03:51AM +0100, Chris Wood wrote: > I'm new to using SQLObject, Welcome! > 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 program. 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. -- Oleg Broytman http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |