[SOLVED] Help with QSqlQueryModel
-
wrote on 18 Apr 2013, 10:41 last edited by
Hi!
The following query works fine in Sqlite but not in Qt creator.The creator hangs on running the App. After stopping the build it gives a error message _exited with code 62097_
Code snippet below:
@
Select a.name, d.title, b.start_time
From channel a
Join BROADCAST_SCHEDULE b on a.channel_id =b.channel_id
Join CONTENT_INSTANCE c on b.instance_id =c.instance_id
Join CONTENT d on d.content_id = c.content_id
Group By a.name, d.title
@ -
wrote on 18 Apr 2013, 11:14 last edited by
Hi,
Qt Creator is only a IDE; so the problem is related to Qt not Creator.
However in your query I see a GROUP BY instruction and no grouping function like COUNT, MAX, and so on -
wrote on 19 Apr 2013, 03:13 last edited by
Thanks for your reply mcosta.
Even if I don't use the *GROUP BY* instruction, I'm unable to execute the query in Qt. Is it because Qt doesn't support it or is it due to some other reason?
-
wrote on 19 Apr 2013, 07:50 last edited by
HI,
I think you Query has a bad syntax and it's strange you say it works in SQlite. Are you sure of that?
-
Hi,
Did you check the error message from the model ?
-
wrote on 19 Apr 2013, 10:13 last edited by
mcosta
Yes I've tried it in SQlite and it works very well.
SGaist
There's no particular error message. The app runs but I don't see the UI window. That's when I stop the app and it gives exited with code 62097 in the output pane
-
If you don't set the query, does you ui show ?
-
wrote on 19 Apr 2013, 11:20 last edited by
bq. Yes I’ve tried it in SQlite and it works very well.
What is the result? I think your query has a incorrect syntax.
-
wrote on 22 Apr 2013, 02:52 last edited by
SGaist
Yes the UI shows if my query is something like
@
select name from channel
@That's why I was wondering if Qt supports complex SQL queries.
mcosta
The result is the name, title and start_time fields like
NAME | TITLE | START_TIME
ESPN | NBA Basketball | UTC Time
ESPN | Up to the minute | UTC Time
Family Net | The cry of the owl | UTC Time -
In that case, print what your model.lastError().text() returns. It should give you an idea why it doesn't work.
-
wrote on 23 Apr 2013, 06:07 last edited by
Hi SGaist
The lastError returns 0. I tried a variation of the code I originally posted and it worked. Here's the code
@
Select d.title
From channel a
Join BROADCAST_SCHEDULE b on b.channel_id = 30
Join CONTENT_INSTANCE c on b.instance_id =c.instance_id
Join CONTENT d on d.content_id = c.content_id
Group By b.start_time
@However, I needed to use a where clause to specify a condition. But when used with this clause, the result is nil. There's no error either.
@
Select d.title
From channel a
Join BROADCAST_SCHEDULE b on a.channel_id = b.channel_id
Join CONTENT_INSTANCE c on b.instance_id =c.instance_id
Join CONTENT d on d.content_id = c.content_id
where a.name like "HBO"
Group By b.start_time
@Does Qt not support where clauses? Where am I going wrong? Thanks for your help.
-
How do you write the last one in your code ?
-
wrote on 23 Apr 2013, 10:34 last edited by
Like this
@
QSqlQuery *query = new QSqlQuery();
QString title = "HBO";
query->prepare (Select d.title
From channel a
Join BROADCAST_SCHEDULE b on a.channel_id = b.channel_id
Join CONTENT_INSTANCE c on b.instance_id =c.instance_id
Join CONTENT d on d.content_id = c.content_id
where a.name like %1
Group By b.start_time).arg(title);
query->exec();
@ -
-
Another thing, is HBO the complete name ? Or is it in the name ? Like "something HBO" ?
In the later case you have to add % to your like statement, see "this":http://www.w3schools.com/sql/sql_like.asp
-
wrote on 25 Apr 2013, 03:07 last edited by
Thanks SGaist for the w3schools.com link. It was very useful to me to learn how to find a particular pattern from a column in the database. Anyhow, pertaining to the problem I was trying to solve, I used
@
where a.name like '%1'
@instead of
@
where a.name like %1
@and it works perfectly well. Thank you very much for correcting my syntax. I didn't know the single quotes were necessary. Thanks again :)
-
You're welcome !
SQL syntax is very sensitive to these kind of details
2/17