<div class="gmail_quote">On Sun, Jan 17, 2010 at 5:36 PM, Dennis Lee Bieber <span dir="ltr"><<a href="mailto:wlfraed@ix.netcom.com">wlfraed@ix.netcom.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I don't think that would be efficient, considering that "the above"<br>
entails what would be something like three or four courses all by<br>
themselves (Database Analysis, Database Design, SQL [these three are<br>
independent of any particular implementation language, though Design and<br>
SQL may be impacted by the database engine one is using -- for example,<br>
foreign key integrity & cascading deletes are not enforced by MySQL<br>
MyISAM tables, but can be enforced using InnoDB tables; SQLite doesn't<br>
have user access levels, but all client/server engines do, etc.), and<br>
then a course on Python with an emphasis on Web applications [since I<br>
recall you are trying to generate HTML at some stage]) the only example<br>
I'd be able to give would require me writing a complete application --<br>
the last time I supplied a large snippet of pseudo-code it took over a<br>
month of daily questions and replies to fix your attempts to modify it;<br>
most problems coming down to not understanding the algorithm, how to use<br>
parameterized queries, etc.<br></blockquote><div><br>LOL! Yeah... <:-} <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
The shortest hints I can demonstrate -- using a text console for<br>
input, AND in pseudo-code (I've not ensured this will run) would be:<br>
<br>
DON'T:<br>
tname = raw_input("Enter the name of the table to be searched: ")<br>
fname = raw_input("Enter the name of the field in %s to be searched: "<br>
% tname)<br>
fvalue = raw_input("Enter the value of %s defining the desired data: "<br>
% fname)<br>
<br>
SQL = """select * from %s<br>
where %s like "%%%s%%"""" % (tname, fname, fvalue)<br>
crs.execute(SQL)<br>
<br>
<br>
DO<br>
tables = [ "Table1",<br>
"Table2",<br>
"Table3" ]<br>
fields = { "Table1" : [ "t1field1",<br>
"t1field2",<br>
"t1field3" ],<br>
"Table2" : [ "t2field1",<br>
"t2field2",<br>
"t2field3" ],<br>
"Table3" : [ "t3field1",<br>
"t3field2",<br>
"t3field3" ] }<br>
<br>
for i, t in enumerate(tables):<br>
print "%s\t%s" % (i, t)<br>
tnum = int(raw_input(<br>
"Enter the number of the table to be searched: "))<br>
tname = tables[tnum]<br>
<br>
for i, f in enumerate(fields[tname]):<br>
print "%s\t%s" % (i, f)<br>
fnum = int(raw_input(<br>
"Enter the name of the field in %s to be searched: "<br>
% tname)<br>
fname = fields[tname][fnum]<br>
<br>
fvalue = raw_input("Enter the value of %s defining the desired data: "<br>
% fname)<br>
<br>
SQL = """select * from %s<br>
where %s like %%s""" % (tname, fname)<br>
crs.execute(SQL, ("%"+fvalue+"%",))<br>
<br>
In a real application, one would use the ability of the database<br>
engine itself to retrieve the list of table names, and the fields for<br>
each table -- that way the code would not need to be changed if the<br>
database has additions or deletions of tables/fields.<br>
<br>
Also note that I did NOT include exception handling -- all those<br>
raw_input() in the "DO" version should have some exception handling (the<br>
first two might not be given numeric data so the int() fails, or the<br>
integer supplied may not be in the range of indices for the list<br>
look-ups; all three might get an EOF entry by the user trying to abort<br>
the look-up.<br>
<br>
Fancier versions would build multi-table joins, or allow for AND (or<br>
OR) clauses in the WHERE, using a list of table.field/value pairs.<br></blockquote><div><br>Thanks. I think I followed that :/<br>beno<br>
</div></div>