do you can to help me on this code?

15 views
Skip to first unread message

נתי שטרן

unread,
Nov 30, 2020, 12:55:06 AM11/30/20
to desertpy
the code:

def create_connection():
    """ create a database connection to the SQLite database
        specified by the db_file
    :param db_file: database file
    :return: Connection object or None
    """
    conn = None
    try:
        conn = sqlite3.connect('my1db.sqlite')
        return select_all_tasks(conn)
    except Error as e:
        return e

    return conn
def select_all_tasks(conn):
    """
    Query all rows in the tasks table
    :param conn: the Connection object
    :return:
    """
    cur = conn.cursor()
    cur.execute("SELECT  line.text,result.filePath,line.number  from line,result")

    rows = cur.fetchall()
    for row in rows:
        a=a+row+'<br>'
    return a

Randy K

unread,
Nov 30, 2020, 5:47:59 PM11/30/20
to desertpy
a needs to be defined first before your for loop. Don't remember off the top of my head if the rows in fetchall are strings, so you might have a problem there, too, so:

rows = cur.fetchall()
a = ""
for row in rows:
    a=a+row+'<br>'

You could also remove the for loop and do this instead:
tag = '<br>'
a = tag.join(rows) + tag

Again, if the elements of "rows" is not usable as a string, you'll have to extract the data you want from each row element.

Your create_connection() function is a little odd, too. It doesn't actually return a connection. It either returns the results of your select or the exception it catches. There is no path to "return conn" as written. Additionally, Error is not defined in python. You probably mean "Exception", but instead of swallowing the exception and using it as a return value, it's likely best to let the exception get handled in the caller logic.

I tested NONE of this, so please excuse any errors which are likely typos.

נתי שטרן

unread,
Dec 1, 2020, 7:27:59 AM12/1/20
to desertpy
I tried but isn't succeed
ב-יום שלישי, 1 בדצמבר 2020 בשעה 00:47:59 UTC+2, Randy K כתב/ה:
Reply all
Reply to author
Forward
0 new messages