adamlofts / mysql1_dart

MySQL driver for Dart
Other
134 stars 45 forks source link

STORED PROCEDURE BUG #113

Open SavageTee opened 2 years ago

SavageTee commented 2 years ago

using stored procedures one after another gives unexpected behavior here is my code ...

import 'package:flutter/material.dart';
import 'package:mysql1/mysql1.dart';

void main() {
  runApp(MaterialApp(home: const SQL(),));
}

class SQL extends StatefulWidget {
  const SQL({Key? key}) : super(key: key);
  @override
  _SQLState createState() => _SQLState();
}

class _SQLState extends State<SQL> {
  @override
  var Connection;

 void initsql() async{
   try{
     var settings =  ConnectionSettings(
         host: "192.168.1.107",
         port: 3306,
         user:  "root",
         password: "Teee",
         db: "nano-inventory1",
         timeout: Duration(minutes: 2)
     );
     Connection = await MySqlConnection.connect(settings);
     print("Connected");
   }catch(e){
     print(e);
   }
  }
  void initState(){
    initsql();
    super.initState();
  }
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
             RaisedButton(onPressed: () async{
               var fto = await Connection.query("CALL Flutter_GetFromTo(3);");
               print(fto);
               var fti = await Connection.query("CALL Flutter_GetServerId(3);");
               print(fti);
               var paty = await Connection.query("CALL Flutter_GetPayments(3);");
               print(paty);

             })
          ],
        ),
      ),
    );
  }
}

when pressing button to call the three stored procedure and print each result i get the following

I/flutter ( 6271): (Fields: {outletfrom: 00, outletto: 11}) >> Result of the first call I/flutter ( 6271): () >> Second call is empty I/flutter ( 6271): (Fields: {serverid: 1}) >> The third result is the result of the second call

LStienon commented 1 year ago

YES i'm currently suffering from the exact same problem. In my app, i'm calling multiple times my service class, that first fecthes all of some of my instances, then fetches only a specific one. Two queries to the database, and two stored procedures. Never had no problem with calling service functions rapidly in time, but here i call both async functions to resolve a future builder and it seems like the queries are overlaping each other : the fetch one returns me ALL of the instances, si it gives me the result of the last query ... i can use a workaround by adding a delay between the queries, or changin strategy by opening a new connection to the database every time i call a service function, so before every query (but this solution is less performant, as it requires to reconnect often, even though i know its a common practice in some extent)

If anybody knows anything about this weird phenomena, i'd be happy to know more about it : its been driving me crazy for days ...

SavageTee commented 1 year ago

YES i'm currently suffering from the exact same problem. In my app, i'm calling multiple times my service class, that first fecthes all of some of my instances, then fetches only a specific one. Two queries to the database, and two stored procedures. Never had no problem with calling service functions rapidly in time, but here i call both async functions to resolve a future builder and it seems like the queries are overlaping each other : the fetch one returns me ALL of the instances, si it gives me the result of the last query ... i can use a workaround by adding a delay between the queries, or changin strategy by opening a new connection to the database every time i call a service function, so before every query (but this solution is less performant, as it requires to reconnect often, even though i know its a common practice in some extent)

If anybody knows anything about this weird phenomena, i'd be happy to know more about it : its been driving me crazy for days ...

at last i used this workaround by disconnect/reconnect at every query