Aug-28-2017, 12:03 AM
Chris,
It has been some time since I've done database work and time has not permitted me to read this entire thread... but if you could answer a few questions...
1 - What kind of database are you trying to query? Is it written in Python ( or an off the shelf product?
2 - Is it a flat-file (single table) or a relational db (set of tables) linked together by primary keys or what?
3 - Are you querying a single table in the db or are attempting to query multiple tables?
4 - If a single table roughly how many records (rows)? 100, 1,000, 10,000 or more?
5 - Ditto for the record set you would expect to get back from a multi-table query
6 - Considering the resultant record set a virtual table are you attempting to...
.. search for the first row that contains the "target text" in column N...
.. then examine Column N in the previous row to see if it is either null or blank?
7 - If the rows are un-ordered how can you write a query to look for the "previous" row ? (Maybe that is your question)
8 - Have you considered...
.. importing one row at at time into a simple python list variable...
.. use a Python counter keep up with what row is the current row...
.. then examining the n'th element of that list for your target...
.. and if found...
.. read in the previous row and examine the same element to see if it is null or blank.
.. if not found import the next row of the table into the list variable and inc the counter and repeat... or whatever
# Basically ( I think) you would
.. use SQL to return the ROW and Python to put the results into a "list"
.. use Python to keep up with which ROW is the current row under investigation
.. use Python to examine the n'th element of the list
.. etc
I'm probably way off here as haven't done any db work in a long time and am very new to Python... but maybe answering my questions and reading my comments will spark an idea.
Actually I'm asking this as I am interested in using Python with a database I have in mind... also just Googled and see SQLite3... is that what you are working with?
It has been some time since I've done database work and time has not permitted me to read this entire thread... but if you could answer a few questions...
1 - What kind of database are you trying to query? Is it written in Python ( or an off the shelf product?
2 - Is it a flat-file (single table) or a relational db (set of tables) linked together by primary keys or what?
3 - Are you querying a single table in the db or are attempting to query multiple tables?
4 - If a single table roughly how many records (rows)? 100, 1,000, 10,000 or more?
5 - Ditto for the record set you would expect to get back from a multi-table query
6 - Considering the resultant record set a virtual table are you attempting to...
.. search for the first row that contains the "target text" in column N...
.. then examine Column N in the previous row to see if it is either null or blank?
7 - If the rows are un-ordered how can you write a query to look for the "previous" row ? (Maybe that is your question)
8 - Have you considered...
.. importing one row at at time into a simple python list variable...
.. use a Python counter keep up with what row is the current row...
.. then examining the n'th element of that list for your target...
.. and if found...
.. read in the previous row and examine the same element to see if it is null or blank.
.. if not found import the next row of the table into the list variable and inc the counter and repeat... or whatever
# Basically ( I think) you would
.. use SQL to return the ROW and Python to put the results into a "list"
.. use Python to keep up with which ROW is the current row under investigation
.. use Python to examine the n'th element of the list
.. etc
I'm probably way off here as haven't done any db work in a long time and am very new to Python... but maybe answering my questions and reading my comments will spark an idea.
Actually I'm asking this as I am interested in using Python with a database I have in mind... also just Googled and see SQLite3... is that what you are working with?