Carl Karsten wrote:
> I now have most of the functionality I was shooting for - run the SQL code
> bellow to create 4 test db's  and then various scenarios:   no access, no 
> table,
> no rows, 2 rows - then run the 'app' ....

Oh yeah, the app:

# uloop2.py

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

# connect, for each db, execute sql and dump results

import dabo

app = dabo.dApp(UI="wx")
app.setup()

user = 'testUserA'

ci = dabo.db.dConnectInfo(DbType='mysql',
                Host='localhost',
                User=user,
                PlainTextPassword='pw' )

sqlCmd = """
select *
    from tbl1
"""
parms={}

conn = dabo.db.dConnection(ci)
dbCur = conn.getDaboCursor()
resultsCur = conn.getDaboCursor()

# get db's
dbCur.execute("""
select distinct table_schema, 0 as rows, '' as results
  from information_schema.SCHEMA_PRIVILEGES
  where GRANTEE like %(user)s
""", {'user':'%'+user+'%'} )

dbs=dbCur.fetchall()
# for each db the user has rights too...
for row in dbs:
     print row['table_schema']
     # use the db, execute the command
     try:
         resultsCur.execute('use %(table_schema)s' % row )
         resultsCur.execute(sqlCmd,parms )
         # log the results
         row['results']=resultsCur.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

app.MainForm = frm

# event loop
app.start()


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Reply via email to