i'm looking for a way to retrieve real database type name from qtsql model.
Unfortunately
QVariant::typeToName(field.type())
Where field is QSqlField type
gives me already mapped type to some Qt type. Is it possible to get real names using Qt?
i found a way to retrieve the real database type with following query:
QSqlQuery query("PRAGMA table_info(tableName)");
As a result you will get:
cid|name |type |notnull |dflt_value |pk
0 |id |integer |0 | |1
1 |name |varchar(45) |1 | |0
thanks to this post:
Getting the type of a column in SQLite
Hope this helps
Related
I have to automate the scenarios that require lot of pre-Req data before verification of expected results.
For Example
Scenario: Scenario1
When I add Data for Order of type 1
|name | Quantity| values|
|A |1 | 2 |
And I add Data for Order of type 2
|name | Quantity| values|UOM |
|A |1 | 2 | mg |
And I add Data for Order of type 3
|name | Quantity| values|UOM |Deliver|
|A |1 | 2 | mg |Home|
Can I use datatables for each Order creation steps. Will it be efficient to use datatable or i should use list.
When cuking you should not put your data in your feature files. Instead you should name your data and refer to the data in your feature files by using the name.
You can then define your data in code in your step definitions, (or better still in a helper method).
This allows you to write features that focus on WHAT you are doing and WHY that is important, rather than on HOW you are doing something.
If you aren't interested in expressing WHAT you are doing and WHY its important you should probably not bother using Cucumber and use a unit testing tool instead. Its much easier to deal with complex data in unit tests because unit tests are written in code, so you can easily do things like
import data from elsewhere
use loops to construct data
use structures to define data
...
Needing to know if this is possible.
I'm trying to get a hierarchical output looking like this:
TITLE|CHART|FUND|ORGN|PROGRAM
S |S |null|null|
S |S |1 |null|
S |S |1 |10 |
S |S |1 |10 |1
S |S |2 |null|
Is this possible to accomplish in SQL Oracle?
I can't figure out the proper verbiage for this and that's why I'm asking here.
Your sample result doesn't look hierarchical,
hierarchical queries usually have a tree structure and a CONNECT BY clause.
You can probably get the required result by using the ORDER BY clause as follows:
SELECT TITLE, CHART, FUND, ORGN, PROGRAM
FROM employers_data_table
ORDER BY TITLE
,CHART
,FUND ASC NULLS FIRST
,ORGN ASC NULLS FIRST
,PROGRAM ASC NULLS FIRST
In case anyone comes across this, the answer I found was to use unions.
Thanks Crowne for your answer, it definitely helped.
I am an absolute beginner in Bigquery and SQL so apologies if this is a dumb question. I have a bigquery table like this
|Name|Value1|Value2|Value3|Value4|Value5|Value6|
|Ben |19 |45 |null |19 |13 |null |
|Bob |34 |null |12 |null |45 |43 |
My query only selects one row that matches the name in Name column. I want the result to only display columns that have non null values. For example if I do
SELECT * FROM mytable WHERE Name = "Bob"
I want the result to look like
|Name|Value1|Value3|Value5|Value6|
|Bob |34 |12 |45 |43 |
Similarly, if I select for Ben I want the result to look like
|Name|Value1|Value2|Value4|Value5|
|Ben |19 |45 |19 |13 |
I have tried SELECT IF but don't seem to get the syntax right.
You cannot select a variable amount of columns, but you may be able to create a SQL, with a combination of aggregate/pivot functions. You may be spending more time than it's worth trying to do it. I spend about two hours on the documentation, and I still feel almost clueless (If doesn't help that I don't have an account there, and my own database does not have the same exact functions).
See Google's BigQuery Documentation for examples.
I think you may be able to do it with UNNEST() and ARRAY(), but you'll lose the original column header information in the process.
I doubt if it can be achieved, because any SQL statement will act on record(s),i.e various columns, so if a column is null, it will affect all columns in the record that are to be retrieved. SQL STATEMENTS RETRIEVE ROWS(COLUMNS REFERENCED)
You can not do that dynamically in SQL. If you need a query like that you could create it manually but it depends on the results you want to achieve.
In the case you showed for example, the query below would work but you would lose the table's header reference.
SELECT value1,value2,value4,value5 FROM mytable WHERE value3 IS NULL AND value6 is NULL
UNION ALL
SELECT value1,value3,value5,value6 FROM mytable WHERE value2 IS NULL AND value4 is NULL
In this example it's possible to see that this kind of query is complicated to build if you have many conditions. Besides that, UNION ALL will always need the same number of columns in each separate query to work. If you need to create a generic query to do that, it's not gonna be possible.
I hope it helps
I have a table that contains a column with comma separated values. I need to separate those values into new rows. Table looks like this :
ID| DATE|Value|Feed|
1|10-10-2014|5.00 |1,3,4
2|10-11-2014|21.00|1
54|01-15-2015|8.24 |2,15
1|02-22-2015|5.14 |1,3,4
And I need to break it out to :
ID| DATE|Value|Feed|
1|10-10-2014|5.00 |1
1|10-10-2014|5.00 |3
1|10-10-2014|5.00 |4
2|10-11-2014|21.00|1
54|01-15-2015|8.24 |2
54|01-15-2015|8.24 |15
1|02-22-2015|5.14 |1
1|02-22-2015|5.14 |3
1|02-22-2015|5.14 |4
So I believe I need a to write a table valued function but I'm having a difficult time figuring out where to start.
Any guidance would be great.
Thanks.
You are going to need the ID so that you can join back to your table, but here is some help for the Split function https://stackoverflow.com/a/10914602/3854195
EDIT: (How to use a cursor to combine the results from the Split function with your source table)
I setup this SQL Fiddle
We are facing a weird problem with one of our query.
Below is the query we are running
INSERT into test
SELECT
member.name as mem_name,
CASE WHEN ( member.dob>0 AND length (member.dob)=8 ) THEN (DATEDIFF(year,to_date("dob",'YYYYMMDD'), to_date(20140716,'YYYYMMDD'))) WHEN ( member.dob=0 ) Then 0 END As Age,
20140716021501
FROM
member
Below is the sample data present in our table.
|name |dob
|Ajitsh |0 |
|rk |51015 |
|s_thiagarajan |19500130 |
|madhav_7 |19700725 |
|1922 |0 |
|rekha |25478 |
|vmkurup |0 |
|ravikris |19620109 |
|ksairaman |0 |
|sruthi |0 |
|rrbha |19630825 |
|sunilsw |0 |
|sunilh |0 |
|venky_pmv |19701207 |
|malagi |0 |
|an752001 |0 |
|edsdf |19790201 |
|anuanand |19730724 |
|fresh |19720821 |
|ampharcopharma |19590127 |
|Nanze |19621123 |
The date of birth is stored in bigint as YYYYMMDD format.
In the data there are some rows, in which date is invalid like 0, 51015.
On some instances this query raises the following error.
INSERT INTO test not successful
An error occurred when executing the SQL command:
INSERT into test
SELECT
member.name as mem_name,
CASE WHEN ( member.dob>0 AND length (member.dob)=8 ) THEN (DATEDIFF(y...
ERROR: Data value "0" has invalid format
Detail:
-----------------------------------------------
error: Data value "0" has invalid format
code: 1009
context: PG ERROR
query: 92776
location: pg_utils.cpp:2731
process: query1_30 [pid=1434]
-----------------------------------------------
Execution time: 3.99s
1 statement failed.
But the strange thing is, it raises the error randomly and not all the time.
Many times it works without any change in query or dataset.
Sometime it also works in second or third attempt.
My doubt is that to_date function is giving this error. But why randomly
and not gives error on every run.
To support my assumption I also tried this small query.
SELECT to_date(20140716,'YYYYMMDD'), to_date(0,'YYYYMMDD');
But this also creates the same scenario. It raises error randomly, while
runs smoothly rest of the times.
If is it fine to ignore this type of values and just convert this to Date format you can follow the below way.
SELECT to_date('20140716','YYYYMMDD'), to_date('0','FMYYYYMMDD');
Here FM suppresses leading zeroes and trailing blanks that would otherwise be added to make the output of a pattern be fixed-width.