mardi 16 février 2016

Ionic sqlite error on select request, returns null

i have an issue when i try to get a row from my Database, i'm saving a profile data in a table called "Learners" when i save it, i don't get any problem, but if i call a Select request it returns me a NULL object, so i don't know where is the error, this is my code fragment:

Controller.js

$scope.getProfileWord2 = function(){
            return Words.getProfileWord().then(function(detalle){
              if (!detalle) {
                $scope.profileWord = {
                  Id_words: null
                };  
              }else{
                $scope.profileWord = detalle;
              }
              return detalle;
            });    

        };
$scope.getProfileWord2().then(function(detalle) {
                                                    if (detalle===null || detalle===undefined) {
                                                    $scope.profileWord = {
                                                      title: null,
                                                      Id_words: null
                                                     };  
                                                    console.log("El Id Word es : " + $scope.profileWord.Id_words);
                                                    //return "/app/inicio";
                                                  }else{
                                                      console.log("El Id Word es : " + $scope.profileWord.Id_words);
                                                      $scope.profileWord = detalle;
                                                      $scope.profile={
                                                        name_sound_path: src,
                                                        word_id: $scope.profileWord.Id_words,
                                                        profile_image_path: $scope.imgURI,
                                                        congrats_path: src2,
                                                        title: content,
                                                        content: content,
                                                        letter_id: $scope.profileLetter.Id,
                                                        selected: 1

                                                      };
                                                      Words.addProfile($scope.profile);
                                                            
                                                  }
                                                  });

Notice in this line Words.addProfile($scope.profile); i use the service.js to add a row to the DB

Service.js

 self.addProfile = function(word) {
    var parameters = [word.name_sound_path,word.word_id,word.profile_image_path,word.congrats_path,word.title,word.content,word.letter_id,word.selected];
    return DBA.query("INSERT INTO learners (name_sound_path, word_id, profile_image_path, congrats_path, title, content, letter_id, selected) VALUES (?,?,?,?,?.?,?,?)", parameters);
  };

Then when i call my controller i call this fucntion, which is called at begin:

$scope.getProfileRow = function() {
    Words.getProfileSimple().then(function(single){
      if (single === null || single === undefined) {
      $scope.editWordRow = {
          title: null,
          congrats_path: null,
          name_sound_path: null,
          profile_image_path: null
      };  
      
      }
      else 
      {
      $scope.editWordRow = single;
     
      }
  
          
    });
      
  };
  $scope.getProfileRow();

that function execute a Select from Database using this service function:

self.getProfileSimple = function() {
    return DBA.query("SELECT * FROM learners WHERE selected = 1")
      .then(function(result) {
        return DBA.getById(result);
      });
  };

When i save a profile data, i set "selected" value to 1, so if i saved the profile data, why the select request is returning NULL, i will appreciate any help, regards...

Aucun commentaire:

Enregistrer un commentaire