0

I'm using python in TestComplete to conduct a db query, but the results seem to be empty strings and do not match the data in the table I queried. The file is a s3db file. Does that matter?

Using:

TestComplete Version 14

imported sqlite3 into python file

I've:

-Tried running the same query in SQLite. It returned the expected result

-Verified the connection is established with the correct db

---python
import sqlite3

def getInfo():
    conn = sqlite3.connect(db)
    c = conn.cursor()

    try:
        c.execute('SELECT Column_Name FROM Table_Name')
        results = c.fetchall()
    except:
        Log.Error("Query execution failed") 

    for x in results:
        Log.Message(x) `enter code here`
        #Log.Message() works like a print statement in testcomplete.
---   

Actual Output: The program runs without errors, but the results come back as 15 lines of blank rows. 15 is the number of records within the table, so I know it's looking in the right place, but it seems like it's not identifying that there's information stored here.

Expected Output: 15 lines of data contained within the Column I specified in the query.

1 Answer 1

-1

There is no error with sqlite3 and your DB operations. The issue is with Log.Message and what it expects as an argument. Within TestComplete, Log.Message requires variable arguments of type Variant, which can be any of the supported data types within TestComplete; String, Double/Real, Boolean, Date/Time, Object (i.e. TestComplete-recognised UI objects) and Integer. Log.Message cannot accept arguments of the type returned by cursor.fetchall's rows.

So you'd need to convert each row into a String, e.g.

for x in results:
    msg = ('{0} : {1}'.format(x[0], x[1]))
    Log.Message(msg)
Sign up to request clarification or add additional context in comments.

2 Comments

If the imported sqlite3 library wasn't working, wouldn't it have thrown an error?
@bonzi You are correct, it would - e.g. if you try to "import sqlite" TC errors out in an expected fashion. As such, my original answer - pertaining to placing external packages in <TestComplete>\Bin\Extensions\Python\Python36\Lib - is not applicable. The issue is more to do with the type of the result row, and what Log.message expects. See my revised answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.