View Full Version : [Qt4.5] MySql strange beheavior

2nd April 2009, 16:25
My new server has been installed and im using it to test my program with it...

But muy problem is that the tables that shows the contents gets the double of the amount of real records in the database, and beyond of the record 99 nothing is showed on the view...
Same code on SQLite works perfect...
Using it on windows and linux, with a mysql server version 5...

When I try to delete some of the "empty" records, tells me that the row is not fetchable...

Some one has experienced the same problem?

Hiker Hauk
2nd April 2009, 19:03
What will the result be if you use not Qt but the MySQL shell to execute the queries?

2nd April 2009, 19:25
if i get exec the query on sheell all the data gets showed...
I've try using

while( modelo->canFetchMore() )
{ modelo->fetchMore(); }
but the same behavior...
The tableview use a QSqlRelationalTableModel, both tables has correct data, no missing foregin keys...

Hiker Hauk
2nd April 2009, 19:41
Now that query in shell is ok, db is not corrected :)

Try to locate where the problem arises.
Try to write a loop with rowCount() and record(), and output the table content with qDebug(), so that we know if the query result itself is incorrect or it is the view that is not displaying correctly.

2nd April 2009, 19:56
whell seems that the query is the problem, got the same problem with the loops:

for( int i=0; i<modelo->rowCount(); i++ )
for( int j=0; j<modelo->record().count(); j++ )
qDebug( qPrintable( modelo->record(i).value( j ).toString() ) );
qDebug( "--" );
Debug: --
Debug: 99
Debug: Alimentos Balanceados
Debug: mijo
Debug: 3.000
Debug: --
Debug: --The model is contructed like this

setTable( "producto" );
setHeaderData( 0, Qt::Horizontal, "#ID" );
setHeaderData( 1, Qt::Horizontal, "Categoria" );
setRelation( 1, QSqlRelation( "categoria", "id", "nombre" ) );
setHeaderData( 2, Qt::Horizontal, "Nombre" );
setHeaderData( 3, Qt::Horizontal, "Precio de Venta" );
setHeaderData( 4, Qt::Horizontal, "Descripcion" );
setHeaderData( 5, Qt::Horizontal, "Marca" );and the table is

CREATE TABLE `producto` (
`id` bigint(1) NOT NULL auto_increment,
`id_categoria` int(1) NOT NULL,
`nombre` tinytext NOT NULL,
`precio_venta` decimal(6,3) NOT NULL,
`descripcion` text,
`marca` tinytext,
) ENGINE=MyISAM AUTO_INCREMENT=256 DEFAULT CHARSET=latin1the modelo->query().executedQuery() returns
SELECT `producto`.`id`,`relTblAl_1`.`nombre` AS categoria_nombre,`producto`.`nombre`,`producto`.`p recio_venta`,`producto`.`descripcion`,`producto`.` marca` FROM `producto`,`categoria` `relTblAl_1` WHERE (`producto`.`id_categoria`=`relTblAl_1`.`id`)
The query works ok on mysql shell...
qt bug?
Any advice?

15th April 2009, 20:55
The same appens in another query where the result is bigger than 100 records... Code problem? server problem? any ideas?

29th April 2009, 15:37
Can be the problem the version of the mysql server that I'm using? The version is 5.0.17
Can it be that the mysql driver that I have for qt is only compatible with servers < 5??

7th May 2009, 22:32
nop, not a problem with the mysql drivers... I've compiled it from source and there is no change...
Any idea if the names of the fields in the database can this to appen??
I'm running out of ideas...

7th May 2009, 22:52
Same problem with sqlbrowser example from qt sources.... on all tables that have more than 99 records, the others ones are empty