tomyeh/postgresql

Insert Query catchesError when execute

beautybird opened this issue · 0 comments

Hello,-
This is your insert query syntax in manual : -

    conn.execute('insert into crayons values (@id, @color)', {'id': 1, 'color': 'pink'})
         .then((_) { print('done.'); });

I understand that id & color are 2 columns in your DB .

This my PG DB :-

          create table data.usersData(
              dataIdDB serial ,
              dataCateg1DB varchar(30)  default ' ',
              dataCateg2DB varchar(30)  default ' ',
              dataEmailDB varchar(40) not null PRIMARY KEY default '',
              dataPassDB varchar(40) not null default ''
         );

I tried the insert query ,and I'm getting error when executing it ..though select query works fine :

        Future<String> registerNewUser(String email, String password) async {

        connectionPool = Persist()._getConnectionPool();

        Persist().poolMessages(connectionPool);

        await connectionPool.start().then((_) {

         connectionPool.connect().then((conn) {
        
         conn
            .query( 'select dataemaildb from data.usersData where dataemaildb=@emailValue
            order  by   dataIdDb',  {'emailValue': email}) .toList() 
            .then((selectResult) {

         // Select Query Works Fine and I get result

          if (selectResult.isEmpty == true && selectResult.length <= 0) {
            
            // I reach to hear ..all fine 
            
            conn.execute('insert into data.usersData values(@dataemaildb,@datapassdb)',
                [{'dataemaildb': email},{'datapassdb': password}])
               .then((insertResult) {
              
              // Here insert query fails and catchesError
              if (insertResult > 0) {
                registerString = 'reg';
              } else if (insertResult == null || insertResult <= 0) {
                registerString = 'nop';
              } else {
                registerString = 'nop';
              }
             
            }).catchError((insertError) {  //When insertQuery I catch Error !!
              registerString = 'nop';
              insertError.toString();
              
            }).whenComplete(() => Timer(Duration(minutes: 1), () {
                  conn.close();
                }));
          } else if (selectResult.isNotEmpty == true && selectResult.length > 0) {
            registerString = 'fal';
          
          } else if (selectResult == null) {
            registerString = 'nop';
            
          } else {
            registerString = 'nop';
           
          }
        })
        .catchError((selectError) {
          registerString = 'nop';
          selectError.toString();
         
        })
        .whenComplete(() => Timer(Duration(seconds: 10), () {
              conn.close();
            }));
  }).catchError((connectionError) {
    registerString = 'nop';
    connectionError.toString();
    
  }).whenComplete(() => null);
  
}).catchError((poolStartError) {
  registerString = 'nop';
  poolStartError.toString();
  
}).whenComplete(() => null);

  return registerNewUserString;
 }