select请求上的Ionic sqlite错误,返回null

时间:2016-02-17 03:17:56

标签: angularjs cordova sqlite ionic-framework

当我尝试从我的数据库中获取一行时,我遇到了一个问题,我将一个配置文件数据保存在名为" Learners"当我保存它时,我没有遇到任何问题,但如果我调用Select请求它会返回一个NULL对象,所以我不知道错误在哪里,这是我的代码片段:

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);
                                                            
                                                  }
                                                  });




注意这一行Words.addProfile($scope.profile);我使用service.js向数据库添加一行

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);
  };




然后,当我打电话给我的控制器时,我会调用这个函数,这个函数在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();




该功能使用此服务功能执行从数据库中选择:



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




当我保存个人资料数据时,我设置"选择"值为1,所以如果我保存了配置文件数据,为什么select请求返回NULL,我将感谢任何帮助,问候......

0 个答案:

没有答案