Solved Socket is closed but first query always return empty
hayatoyu opened this issue · 7 comments
I encountered the Socket Closed Exception and I follow the #105 to solve it.
But now I encountered another issue that the first query is always empty. Just like the #106
The code is very simple as below:
var settings = ConnectionSettings.socket( path: '192.168.3.64', user: 'hayato', password: 'coai62l3', db: 'test', characterSet: CharacterSet.UTF8, useCompression: false, useSSL: false, maxPacketSize: 16 * 1024 * 1024 ); var conn = await MySqlConnection.connect(settings); var results = await conn.query("select * from users"); var results2 = await conn.query("select * from users"); for(var row in results) { print(row); } for(var row in results) { print(row); } conn.close();
There is actually a record in table, but the $results is empty and the $results2 is correct.
Did anyone encouter the same problem and solved it?
I encountered the Socket Closed Exception and I follow the #105 to solve it. But now I encountered another issue that the first query is always empty. Just like the #106
The code is very simple as below:
var conn = await MySqlConnection.connect(settings);
var results = await conn.query("select * from users");
var results2 = await conn.query("select * from users");
for(var row in results) {
print(row);
}
for(var row in results2) {
print(row);
}
conn.close();There is actually a record in table, but the $results is empty and the $results2 is correct. Did anyone encouter the same problem and solved it?
Yes i encountered the same issue please let me know if anyone found solution regarding it
Yes i encountered the same issue please let me know if anyone found solution regarding it
+1 here!
+1
Max priority bug for me, it returns the "previous" query.
var results1 = await conn.query("select * from user");
var results2 = await conn.query("select * from city");
var results3 = await conn.query("select * from country");
results1 will be empty
results2 will contain the users
results3 will contain the cities
i had this issue too. this occurs when you try to fetch data before connection has initialized.
try to implement like this..
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:mysql_utils/mysql1/src/single_connection.dart';
import 'package:mysql_utils/mysql_utils.dart';
class Homepage extends StatefulWidget {
const Homepage({Key? key}) : super(key: key);
@override
_HomepageState createState() => _HomepageState();
}
class _HomepageState extends State<Homepage> {
MysqlUtils? db;
@override
void initState() {
super.initState();
initializeDatabase();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body:
Center(
child: TextButton.icon(
onPressed: () {
log("pressed");
db!=null?getDatafromdatabase():ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text("Please wait a second..")));
},
icon: const Icon(Icons.get_app),
label: const Text("get data!")),
),
);
}
void getDatafromdatabase() async {
Results row = await db!.query('SELECT * FROM mydetails',[]);
log(row.toString(), name: "results");
for (var element in row) {
log(element.fields['name'],name: "element values");
}
}
void initializeDatabase(){
MysqlUtils(
settings: ConnectionSettings(
//host: '192.168.23.50',
host: 'localhost',
port: 3306,
user: 'root',
password: '788*$%',
db: 'login',
useCompression: false,
useSSL: false,
timeout: const Duration(seconds: 8),
),
pool: true,
errorLog: (error) {
log("-----$error",name: "error");
},
sqlLog: (sql) {
log("-----$sql",name:"sql");
},
connectInit: (MysqlUtils db1) async{
log("complete");
db=db1;
});
}
}
#88 (comment)
this is a bug but solved