From: Chris W. <c.c...@gm...> - 2009-09-29 08:04:28
|
Dear all, I'm new to using SQLObject, and having some problems with getting it to recognise my current MySQL database. I've set up my connection fine, but it won't recognise the names of the columns (presumably because they're not written using the default naming convention?). For example, one of my columns is an acronym, so is 3 uppercase letters. I've tried the following: class Table1(sqlobject.SQLObject): _connection = conn _fromDatabase = True class sqlmeta: table = 'Table1' idName = 'Table1ID' BOB = StringCol() print Table1.get(1) this gives the result Unknown column 'bo_b' in 'field list' So, specifically a few questions: I've seen the attribute in class sqlmeta of 'columns' - will this find my column names automatically, or do I still need to input them manually? If the latter..: 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? Is there a published list of the default naming convention that SQLObject follows? I couldn't find it on the website. Thanks in advance for any help anyone is able to give. Chris |
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. |
From: Chris W. <c.c...@gm...> - 2009-09-30 08:36:49
|
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? Thanks, Chris 2009/9/29 Oleg Broytman <ph...@ph...> > 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. > > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry® 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-12, 2009. Register now! > http://p.sf.net/sfu/devconf > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > |
From: Oleg B. <ph...@ph...> - 2009-09-30 08:49:34
|
On Wed, Sep 30, 2009 at 09:36:15AM +0100, Chris Wood wrote: > 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? Either try simple (one-to-one) style, or name you columns explicitly. I.e., either class Table1(sqlobject.SQLObject): class sqlmeta: table = 'Table1' idName = 'Table1ID' fromDatabase = True style = styles.Style() _connection = conn or class Table1(sqlobject.SQLObject): class sqlmeta: table = 'Table1' idName = 'Table1ID' _connection = conn BOB = StringCol(dbName='BOB') Oleg. -- Oleg Broytman http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Oleg B. <ph...@ph...> - 2009-09-30 09:35:48
|
(Answering to the list...) On Wed, Sep 30, 2009 at 10:33:18AM +0100, Chris Wood wrote: > class Cruise(sqlobject.SQLObject): > connection = conn > class sqlmeta: > table = Table1 > idName = 'Table1ID' > fromDatabase = True > style = styles.Style() > testList = sqlmeta.columns > > print Cruise.sqlmeta.testList Why do you do this? Why not just print Cruise.sqlmeta.columns ? Oleg. -- Oleg Broytman http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Chris W. <c.c...@gm...> - 2009-09-30 10:28:59
|
Excellent, that works! Thanks. 2009/9/30 Oleg Broytman <ph...@ph...> > (Answering to the list...) > > On Wed, Sep 30, 2009 at 10:33:18AM +0100, Chris Wood wrote: > > class Cruise(sqlobject.SQLObject): > > connection = conn > > class sqlmeta: > > table = Table1 > > idName = 'Table1ID' > > fromDatabase = True > > style = styles.Style() > > testList = sqlmeta.columns > > > > print Cruise.sqlmeta.testList > > Why do you do this? Why not just > > print Cruise.sqlmeta.columns > > ? > > Oleg. > -- > Oleg Broytman http://phd.pp.ru/ ph...@ph... > Programmers don't die, they just GOSUB without RETURN. > > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry® 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-12, 2009. Register now! > http://p.sf.net/sfu/devconf > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > |
From: Oleg B. <ph...@ph...> - 2009-09-30 10:58:29
|
On Wed, Sep 30, 2009 at 11:28:28AM +0100, Chris Wood wrote: > Excellent, that works! Thanks. Good. > 2009/9/30 Oleg Broytman <ph...@ph...> > > > (Answering to the list...) > > > > On Wed, Sep 30, 2009 at 10:33:18AM +0100, Chris Wood wrote: > > > class Cruise(sqlobject.SQLObject): > > > connection = conn > > > class sqlmeta: > > > table = Table1 > > > idName = 'Table1ID' > > > fromDatabase = True > > > style = styles.Style() > > > testList = sqlmeta.columns > > > > > > print Cruise.sqlmeta.testList Now explanation. You have assigned testList long before SQLObject populates sqlmeta.columns. In sqlmeta.setClass() SQLObject reassigns sqlmeta.columns but your testList stays empty. Oleg. -- Oleg Broytman http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Oleg B. <ph...@ph...> - 2009-10-07 17:42:48
|
Hello! Please write to the mailing list. On Wed, Oct 07, 2009 at 04:21:50PM +0100, Chris Wood wrote: > My database already contains intermediate tables of many:many relationships, Many-to-many relations in SQLObject are created using two RelatedJoin's. Explicit intermediate tables are possible, too: http://sqlobject.org/FAQ.html#how-can-i-define-my-own-intermediate-table-in-my-many-to-many-relationship The example in the FAQ uses SQLRelatedJoin's. The difference is that RelatedJoin attributes return a list of rows (SQLObject instances) where SQLRelatedJoin attributes return a SelectResults instance which you can iterate over. Oleg. -- Oleg Broytman http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |