My uLoop util looks like it is almost done:   The test method works, the UI 
mostly works (need some help putting a column of checkboxes in place of a 
column 
of "True", and I need to add more columns,  but that can wait.)

But the underling code is kinda tangled up.  so before I try to fix the grid I 
figured I should do some housekeeping.

In my BO, I do:
     self.dbs = self.conn.cursor._records

I think that is wrong for at least 2 reasons:
1. .conn is my Data Object - I think the BO should not be referencing cursor 
props like that
2. pretty sure none of my code should be referencing any ._attributes.

Similarly my cdxml grid:  DataSource="self.Form.uLoopBO1.dbs"

I am also not sure who should be creating what (BO creates Connection, 
connection creates cursor?)  So i would appreciate it if someone can look over 
my code and tell me what they think.

I preloaded it connect to dabodev - you should see the one database the webuser 
has rights to.  nifty, eh?

Carl K



# uloop3.py

"""executes a query against selected dbs a user has rights to"""

import dabo
from dabo.dLocalize import _

class uLoopDO(dabo.db.dConnection):

   def getDBs(self,user):

     """ get the list of DBs the user has access to """
     self.cursor = self.getDaboCursor()
     rows = self.cursor.execute("""select distinct table_schema
       from information_schema.SCHEMA_PRIVILEGES
       where GRANTEE like %(user)s
       """, {'user':'%'+user+'%'} )
     return rows

   """
   def test(self):
     self.connection = self.something(DbType='mysql',
                 Host='vaio',
                 User='testUserA',
                 PlainTextPassword='pw' )
     print self.getDBs('testUserA')
     print cursor._records
   """

class uLoopBO(dabo.biz.dBizobj):

   def initProperties(self):
     # self.host = 'localhost'
     # self.host = 'sahara'
     # self.user = 'testUserA'
     # self.pw = 'pw'
     self.host = 'dabodev.com'
     self.user = 'webuser'
     self.pw = 'foxrocks'
     self.sqlCmd = 'select * from tbl1'
     self.cursor = None
     self.dbs = []

   def findDBs(self):
     ci = dabo.db.dConnectInfo(DbType='mysql',
       Host=self.host,
       User=self.user,
       PlainTextPassword=self.pw )

     self.conn = uLoopDO(ci)
     self.conn.getDBs(self.user)
     self.dbs = self.conn.cursor._records

     # for each db the user has rights to
     # add a 'selected' for the grid
     for row in self.dbs:
         row['selected']=True

   def runCommandOnDBs(self):
     # for each db the user has rights too...
     for row in self.conn.cursor._records: # self.dbs:
         # print row['table_schema']
         # use the db, execute the command
         try:
             self.conn.cursor.execute('use %(table_schema)s' % row )
             self.conn.cursor.execute(self.sqlCmd)
             # log the results
             row['results']=self.conn.cursor._records # .fetchall()
             row['rows']=len(row['results'])
         except Exception, e:
             # or log the error
             row['results'] = e
             # row['rows'] = None

         # frm, grd = dabo.ui.browse(dbCur)
         # frm.Caption = 'User: %s' % user

   def test(self):
     self.host = 'sahara'
     self.findDBs()
     self.dbs[0]['selected'] = True
     self.runCommandOnDBs()
     print self.dbs


if __name__ == "__main__":

   # uLoopBO1=uLoopBO(None)
   # uLoopBO1.test()

   app = dabo.dApp(MainFormClass=None)
   app.setup()
   frm = dabo.ui.createForm('uloop.cdxml')
   frm.uLoopBO1=uLoopBO(None)
   frm.show()
   app.start()

<?xml version = '1.0' encoding = 'utf-8' standalone = 'no'?>
<dForm Top="498" designerClass="DesForm" Width="815" Left="224" Height="392" 
Caption="Dabo Class Designer" Name="dForm" UseSizers="True" >
   <dSizer designerClass="LayoutSizer" SlotCount="1" Orientation="Vertical" >
     <dPanel sizerInfo="{'BorderSides': ['All'], 'Proportion': 1, 'HAlign': 
'Center', 'VAlign': 'Middle', 'Border': 0, 'Expand': True}" 
designerClass="controlMix" Width="815" Height="342" >
       <dSizer designerClass="LayoutSizer" SlotCount="3" Orientation="Vertical" 
>
         <dSizer sizerInfo="{'BorderSides': ['All'], 'Proportion': 0, 'HAlign': 
'Left', 'VAlign': 'Top', 'Border': 0, 'Expand': True}" 
designerClass="LayoutSizer" SlotCount="8" Orientation="Horizontal" >
           <dLabel sizerInfo="{'BorderSides': ['All'], 'Proportion': 0, 
'HAlign': 'Left', 'VAlign': 'Top', 'Border': 0, 'Expand': False}" 
designerClass="controlMix" Width="32" Caption="Server" />
           <dTextBox sizerInfo="{'BorderSides': ['All'], 'Proportion': 1, 
'HAlign': 'Left', 'VAlign': 'Top', 'Border': 0, 'Expand': True}" 
DataField="host" designerClass="controlMix" Width="409" Height="34" 
DataSource="self.Form.uLoopBO1" Name="dTextBox2" />
           <dLabel sizerInfo="{'BorderSides': ['All'], 'Proportion': 0, 
'HAlign': 'Left', 'VAlign': 'Top', 'Border': 0, 'Expand': False}" 
designerClass="controlMix" Width="22" Caption="User" Name="dLabel1" />
           <dTextBox sizerInfo="{'BorderSides': ['All'], 'Proportion': 0, 
'HAlign': 'Left', 'VAlign': 'Top', 'Border': 0, 'Expand': True}" 
DataField="user" designerClass="controlMix" Height="34" 
DataSource="self.Form.uLoopBO1" Name="dTextBox1" />
           <dLabel sizerInfo="{'BorderSides': ['All'], 'Proportion': 0, 
'HAlign': 'Left', 'VAlign': 'Top', 'Border': 0, 'Expand': False}" 
designerClass="controlMix" Width="22" Caption="pass" Name="dLabel2" />
           <dTextBox sizerInfo="{'BorderSides': ['All'], 'Proportion': 0, 
'HAlign': 'Left', 'VAlign': 'Top', 'Border': 0, 'Expand': True}" DataField="pw" 
designerClass="controlMix" Height="34" DataSource="self.Form.uLoopBO1" />
           <dButton sizerInfo="{'BorderSides': ['All'], 'Proportion': 0, 
'HAlign': 'Center', 'VAlign': 'Middle', 'Border': 0, 'Expand': False}" 
code-ID="dButton-dPanel" designerClass="controlMix" Caption="Connect" 
Name="dButton1" />
           <dButton sizerInfo="{'BorderSides': ['All'], 'Proportion': 0, 
'HAlign': 'Center', 'VAlign': 'Middle', 'Border': 0, 'Expand': False}" 
code-ID="dButton-dPanel-621" designerClass="controlMix" Caption="Run" />
         </dSizer>
         <dEditBox sizerInfo="{'BorderSides': ['All'], 'Proportion': 1, 
'HAlign': 'Left', 'VAlign': 'Top', 'Border': 0, 'Expand': True}" 
DataField="sqlCmd" designerClass="controlMix" Width="815" Height="155" 
DataSource="self.form.uLoopBO1" />
         <dGrid sizerInfo="{'BorderSides': ['All'], 'Proportion': 1, 'HAlign': 
'Left', 'VAlign': 'Top', 'Border': 0, 'Expand': True}" 
designerClass="controlMix" Width="815" SelectionMode="Cell" Height="154" 
ColumnCount="4" DataSource="self.Form.uLoopBO1.dbs" >
           <dColumn FontFace="Sans" DataField="selected" 
designerClass="controlMix" HeaderVerticalAlignment="None" Width="150" 
HeaderForeColor="None" HeaderFontBold="False" HeaderBackColor="None" 
VerticalAlignment="Top" FontUnderline="False" Editable="False" 
HorizontalAlignment="Left" FontBold="False" Expand="False" FontItalic="False" 
HeaderFontUnderline="False" Order="0" Caption="Column" Sortable="True" 
Searchable="True" HeaderHorizontalAlignment="None" FontSize="9" 
HeaderFontItalic="False" HeaderFontFace="Sans" HeaderFontSize="12" 
ListEditorChoices="[]" />
           <dColumn FontFace="Sans" DataField="table_schema" 
designerClass="controlMix" HeaderVerticalAlignment="None" Width="150" 
HeaderForeColor="None" HeaderFontBold="False" HeaderBackColor="None" 
VerticalAlignment="Top" FontUnderline="False" Editable="False" 
HorizontalAlignment="Left" FontBold="False" Expand="False" FontItalic="False" 
HeaderFontUnderline="False" Order="10" Caption="Column" Sortable="True" 
Searchable="True" HeaderHorizontalAlignment="None" FontSize="9" 
HeaderFontItalic="False" HeaderFontFace="Sans" HeaderFontSize="12" 
ListEditorChoices="[]" />
           <dColumn FontFace="Sans" DataField="" designerClass="controlMix" 
HeaderVerticalAlignment="None" Width="150" HeaderForeColor="None" 
HeaderFontBold="False" HeaderBackColor="None" VerticalAlignment="Top" 
FontUnderline="False" Editable="False" HorizontalAlignment="Left" 
FontBold="False" Expand="False" FontItalic="False" HeaderFontUnderline="False" 
Order="20" Caption="Column" Sortable="True" Searchable="True" 
HeaderHorizontalAlignment="None" FontSize="9" HeaderFontItalic="False" 
HeaderFontFace="Sans" HeaderFontSize="12" ListEditorChoices="[]" />
           <dColumn FontFace="Sans" DataField="" designerClass="controlMix" 
HeaderVerticalAlignment="None" Width="150" HeaderForeColor="None" 
HeaderFontBold="False" HeaderBackColor="None" VerticalAlignment="Top" 
FontUnderline="False" Editable="False" HorizontalAlignment="Left" 
FontBold="False" Expand="False" FontItalic="False" HeaderFontUnderline="False" 
Order="30" Caption="Column" Sortable="True" Searchable="True" 
HeaderHorizontalAlignment="None" FontSize="9" HeaderFontItalic="False" 
HeaderFontFace="Sans" HeaderFontSize="12" ListEditorChoices="[]" />
         </dGrid>
       </dSizer>
     </dPanel>
   </dSizer>
</dForm>


# -*- coding: utf-8 -*-
### Dabo Class Designer code. You many freely edit the code,
### but do not change the comments containing:
###             'Dabo Code ID: XXXX',
### as these are needed to link the code to the objects.

## *!* ## Dabo Code ID: dButton-dPanel
def onHit(self, evt):
   self.Form.uLoopBO1.findDBs()
   print self.Form.uLoopBO1.dbs
   self.Form.update()

## *!* ## Dabo Code ID: dButton-dPanel-621
def onHit(self, evt):
   self.Form.uLoopBO1.runCommandOnDBs()
   print self.Form.uLoopBO1.dbs
   self.Form.update()



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]

Reply via email to