[storm] I need a tutorial that deals with working on an established database.
MRichardson3 at gmail.com
Tue Jul 7 05:03:45 BST 2009
I am a noob. Please go easy on me. I've been searching for a tutorial
that shows how you can work with an existing database.
I.e, the database's schema has already been defined (it's a Joomla
database). I need to be able to select the
table I want, iterate over the rows in the database, change some records
and finally write the changes to those records back out.
All of the tutorials I've been able to find on the Internet seem to show
the user creating the tables from scratch. Having to write
python classes showing how the fields are defined, for example. In my
case, all of that work is done. I want
to open the database, have it give me a list of tables and subsequently
the columns in those tables
and then iterate over all of the rows in the table changing columns as
per needed. Below would be some
hypothetical pseudo code showing what I want to do. I'd like to see some
real world examples that accomplishes
the same task, but written using Storm.
<begin hypothetical code>
database = open('/mysql/joomla.db','rw') # this is way simplified
as I know MYSQL needs a bunch of parameters, but basically I want to
open it in read, write mode.
tablelist = database.tables() #get me the list of
all tables associated with the database
for table in tablelist: # iterate through
all of the tables in the database
columnlist = table.columns() # for each table, return a
list of all of the column names,
rowlist = table.fetchall() # put all rows into a
database list, alternatively I might use the fetchone() option if I want
to do it one by one
for row in rowlist: # now iterate through every
row in the table in the database
row.column(columnlist) = row.column(columnlist) * 0.07 #
for each row in the table, multiply the first column by 7 percent
row.column('AnnualPay') = row.column('AnnualPay') * 0.07
#alternatively, we could directly access the field name if we knew its
#write the row changes back out to the data base table
#close the table and save the changes
#finish with the database.
<end hypothetical code>
I know this pseudo code is extremely terse and probably wrong in some
places, but it gives the flavor of what I want to do. I
just need some simple code showing me how to process every row of a
table in a database. If this question has already been
answered, could you please send me the link to the final discussion. I
may be showing a fundamental lack of understanding
about using a database, but it seems I should be able to manipulate my
database this way if I choose to.
Thank you all,
mrichardson3 @ gmail.com
More information about the storm