@rakesh_mobile_dvlpr wrote:
Hi ! I am new to the Ionic framework .
I have tried to Insert
varchar
into the table and it works as well.But,when I tried to insert date or time ,it shows an error
Prepare statement failed with error 1
.Inside
.ready()
function, the database and table is created as mentioned below,db = $cordovaSQLite.openDB({ name: "rakesh.db"}); $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS employee (firstname text, lastname text,email text,dateOfBirth DATETIME,CheckInTime Time,mobile big integer,designation text)");
Inside the
Controller
, tried to insert the values in two ways as mentioned below,Way 01:
example.controller("ExampleController", function($scope,$cordovaSQLite) { var query = "INSERT INTO employee (firstname,lastname,email,mobile,dateOfBirth,CheckInTime,designation) VALUES (?,?,?,?,?,?,?)"; $cordovaSQLite.execute(db, query, [$scope.employee.firstname, $scope.employee.lastname, $scope.employee.email, $scope.employee.mobile, new Date($scope.employee.dateOfBirth).toISOString(), $scope.employee.checkInTime, $scope.employee.designation ]) .then(function(res) { alert('HURREY ! INSERTED'); }, function (err) { alert('ERROR IN INSERTION ->'+ JSON.stringify(err)); }); }
Way 02:
example.controller("ExampleController", function($scope,$cordovaSQLite) { var query = "INSERT INTO employee (firstname,lastname,email,mobile,dateOfBirth,CheckInTime,designation) VALUES (?,?,?,?,?,?,?)"; $cordovaSQLite.execute(db, query, [$scope.employee.firstname, $scope.employee.lastname, $scope.employee.email, $scope.employee.mobile, '2015-05-05', '23:05:56', $scope.employee.designation ]) .then(function(res) { alert('HURREY ! INSERTED'); }, function (err) { alert('ERROR IN INSERTION ->'+ JSON.stringify(err)); }); }
But,unfortunately the same error is displayed.
Please help me finding the solution.
Posts: 1
Participants: 1