Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert Query catchesError when execute #8

Open
beautybird opened this issue May 15, 2020 · 0 comments
Open

Insert Query catchesError when execute #8

beautybird opened this issue May 15, 2020 · 0 comments

Comments

@beautybird
Copy link

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;
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant