Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 4 and Version 5 of ViewsInSqlObject


Ignore:
Timestamp:
03/13/06 17:29:29 (13 years ago)
Author:
u3292467@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ViewsInSqlObject

    v4 v5  
    6767 
    6868''- Jorge Godoy'' 
     69 
     70------ 
     71 
     72We had some trouble with the above method, but we are trying to do something a little different. 
     73 
     74We already have database schema defined and wanted to use the views we already had defined.  The view was created by: 
     75{{{ 
     76CREATE VIEW collection_metrics AS         
     77    SELECT  
     78        collection_id             AS id, 
     79        SUM(duration)             AS duration, 
     80        SUM(size)                 AS size, 
     81        COUNT(collection_id)      AS files, 
     82        COUNT(DISTINCT item_id)   AS items 
     83    FROM  
     84        files 
     85    GROUP BY 
     86        collection_id 
     87    ORDER BY 
     88        collection_id; 
     89}}} 
     90 
     91 
     92At first I tried this SQLObject: 
     93{{{ 
     94class collectionMetrics(SQLObject): 
     95    class sqlmeta: 
     96        fromDatabase=True 
     97}}} 
     98 
     99Which would fail because SQLObject couldn't find a PRIMARY KEY from the database.  The solution is fairly simple, just manually define the columns, and tell SQLObject which table to use. 
     100 
     101{{{ 
     102class collectionMetrics(SQLObject): 
     103    duration = FloatCol() 
     104    size = FloatCol() 
     105    files = IntCol() 
     106    items = IntCol() 
     107    class sqlmeta: 
     108        table = 'collection_metrics 
     109}}} 
     110 
     111Hope that helps! 
     112 
     113Paul Warren. 2006-03-14