RobotFramework: Getting string value back from sql query - robotframework

Doing a database query that returns multiple rows...
${visits_for_this_patient}= Select from Database
... Select to_char(visit_date, 'YYYY-MM-DD') from patient_visits where patient_id=${patient_id} order by visit_date
${list_of_visits_for_this_patient}= create list ${visits_for_this_patient}
Row Count Should Be Equal To X
... Select * from patient_visits where patient_id=${patient_id}
... ${expected_number_of_patients_for_this_visit}
... ${SPONSOR_NAME}
How can i take a specific row's string value back without the padding? Im getting like
(b'2017-03-03',)
when i try ${visits_for_this_patient[0]}

You have to go one level deeper - the return value of а db query is a list of tuples (that's how the underlying python modules return the data).
E.g. it looks like this:
[(b'2017-03-03',)]
When you call ${visits_for_this_patient[0]}, you get the 1st member of the list - a tuple (what you saw yourself). To get the actual value, just get that value's first member (the 1st member of the tuple); so simply:
${visits_for_this_patient[0][0]}
The end value of that should be 2017-03-03 (as a string).

Related

Is Filter expression in DynamoDB .NET query applied after "page limit" condition is applied?

I am writing a Dynamo Db .NET query with both "Limit" as well as "Filter Expression" as shown below:
var search = testTable.Query(new QueryOperationConfig
{
Filter = new QueryFilter("Name", QueryOperator.BeginsWith, "B"),
IndexName = "IsActive-gsi",
Limit = 5,
PaginationToken = paginationToken,
});
I expect that filter expression should be evaluated first and then limit condition is applied to the filtered result. But query seems to work in other way. That is, Limit condition is getting applied first and then filter expression is applied on the limited result. Due to this, I am not getting the expected result.
For example, say I have 10 rows in a table (with only one column of string type). Say first 5 rows starts with letter "A" and then 6th row starts with letter "B". I have added Limit as 5 and filter expression as "BeginsWith('B')" as shown above in the query. I expect to get at least one result(6th row) but query returns zero results.
My question: Is my query wrong or does Dynamo DB works this way? If it works this way, then how to get around this issue i.e. first apply filter expression on all rows and then apply limit condition, both in a single call to database?
FilterExpression do not actually change the query itself (i.e. all elements that match your query are returned from DynamoDB), but only limit the results afterwards. See the FilterExpression documentation:
A filter expression is applied after a Query finishes, but before the
results are returned.
So this means, that your observed behaviour is the expected behaviour.
I think to get the result you want, you need to make sure that the attribute on which you want to apply a filter is part of the key (i.e. probably the sort key), then you can use Key Condition Expressions.

SQLite C API equivalent to typeof(col)

I want to detect column data types of any SELECT query in SQLite.
In the C API, there is const char *sqlite3_column_decltype(sqlite3_stmt*,int) for this purpose. But that only works for columns in a real table. Expressions, such as LOWER('ABC'), or columns from queries like PRAGMA foreign_key_list("mytable"), always return null here.
I know there is also typeof(col), but I don't have control over the fired SQL, so I need a way to extract the data type out of the prepared statement.
You're looking for sqlite3_column_type():
The sqlite3_column_type() routine returns the datatype code for the initial data type of the result column. The returned value is one of SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, or SQLITE_NULL. The return value of sqlite3_column_type() can be used to decide which of the first six interface should be used to extract the column value.
And remember that in sqlite, type is for the most part associated with value, not column - different rows can have different types stored in the same column.

how to use Queryresult variable as input in other query in robot framework

I am doing 1 simple db connection test in Robot framework.I am doing as following-
${queryResults1} Query <sql query>
now I want to use the value of ${queryResults1} as input to another query. I am doing
Execute Sql String select * from customer where customer_id=${queryResults1}
here I am getting error .Execute Sql String doesnot get value of queryresult
how can I do this ?
thanks in Advance!!!
The problem is that your first query is returning a list of tuples -- a list of rows, each of which is a tuple of columns. Even though you're apparently expecting a single value from a single column in a single row, the data is still in this format. You need to pull the value out of that list of tuples before passing it to your second query.
For example:
Execute Sql String select * from customer where customer_id=${queryResults1[0][0]}

how to resolve 2nd query destroying 1st query that's being iterated over

Using Python 3 and sqlite, I perform a query that gives me results I want to iterate over. But, as part of what I want to do in the iteration, I want to perform a second query. But, when I do the second query, the results from the first query are destroyed by the second query and my script stops iterating over the first query because there is nothing left from the first query to iterate over (hoping this makes sense!). Is it possible to have 2 or more query results in the same script unaffected by each other? Or, what is a good/best way to resolve this issue?
Here's an example of what I mean:
curs.execute('SELECT number1, number2, FROM numbers WHERE ID = 3')
for row in curs:
do this (whatever?)
do this (whatever?)
curs.execute('UPDATE table1 SET ID = "foo" WHERE state = "bar"')
conn.commit()
Not an expert but they should have unique names.

ERROR:-528 MEssage: [Informix .NET provider][Informix]Maximum output rowsize (32767) exceeded

I face the following exception when i try to get data from table with the following structure:
ERROR:-528 MEssage: [Informix .NET provider][Informix]Maximum output
rowsize (32767) exceeded.
CREATE TABLE dr66req
(
req_ser SERIAL PRIMARY KEY,
req_desc LVarChar(32739),
);
Ref:
The total number of bytes that this statement selects exceeds the
maximum that can be passed between the database server and the program.
Try following-
1) Make sure that the columns selected are the ones that you intended.
2) Check that you have not named some very wide character column by
mistake, neglected to specify a substring, or specified too long a
substring. If the selection is what you require, rewrite this SELECT
statement into two or more statements, each of which selects only some
of the fields.
3) If it is a join of several tables, you might best select
all desired data INTO TEMP; then select individual columns of the
temporary table.
4)If this is a fetch via a cursor in a program, you
might revise the program as follows.
First, change the cursor to select only the ROWID of the desired row.
Second, augment the FETCH statement with a series of SELECT statements, each of which selects one or a few columns WHERE ROWID = the saved row ID.

Resources