Solved

Database will not delete

Posted on 2014-02-12
3
164 Views
Last Modified: 2014-06-01
I am using appecelerator  javascript for an android app ... the code wont delete the database .... we count the the lines in the database and send the data to our server ... once the number is zero it erases the database... 1) the database is not being erased so we are sending a lot of duplicate data and an enormous amount the next time user runs our program... as a side note can someone send me a tutorial of how to view the android database ... a really basic one for people new to android. using adb i was able to locate the database file, but not view it or copy the file out of adb to my desktop

var numRequests = '';
var Groundy = function(){
 
var db = Ti.Database.open('FrogMan.db');
var getGroundData = db.execute('SELECT user, MatchUID,Ossys, UserID, SetPrKey, Game, Point, Stroke, XCor, YCor FROM GroundStrokeData');
numRequests = 0;
while (getGroundData.isValidRow())
{
    numRequests++;
     var user = getGroundData.fieldByName('UserID');
     var UserID = getGroundData.fieldByName('UserID');
     var MatchUID = getGroundData.fieldByName('MatchUID'); 
     var Ossys = getGroundData.fieldByName('Ossys');
     var SetPrKey = getGroundData.fieldByName('SetPrKey'); 
     var Game = getGroundData.fieldByName('Game');
     var Point = getGroundData.fieldByName('Point');  
     var Stroke = getGroundData.fieldByName('Stroke'); 
     var XCor = getGroundData.fieldByName('XCor');
     var YCor = getGroundData.fieldByName('YCor');
 
  GroundDtrokeTransmit(user, MatchUID, Ossys, UserID, SetPrKey, Game,  Point, Stroke, XCor, YCor);
  getGroundData.next();
}
 
getGroundData.close();
db.close();
};
 
var GroundDtrokeTransmit = function(user, MatchUID, Ossys,  UserID, SetPrKey, Game, Point, Stroke, XCor, YCor){ 
 
 
var xhr=Titanium.Network.createHTTPClient();    
 xhr.onerror = function(e){ 
 Ti.API.error('groundy Bad Sever =>'+e.error);
};
 
xhr.open("POST", "http://mytenniscoach.net/services/default.php?method=transGround");//ADD your URL
xhr.setRequestHeader("content-type", "application/json");
    params={    "user":user,
                "UserID": UserID,
                "MatchUID":MatchUID,
                "Ossys":Ossys,
                "SetPrKey":SetPrKey,
                "Game" : Game,
                "Point":Point,
                "StrokeUID": Stroke,
                "XCor" : XCor,
                "YCor" : YCor
 
          };
 
Ti.API.info('this is ground stroke data'+JSON.stringify(params));
xhr.send(JSON.stringify(params));
 
 
xhr.onload = function(f){
    numRequests--;
    Ti.API.info(f.error);
    var jObject = JSON.parse(this.responseText);
    if(jObject.Result == 1){
        jsonError=false;
 }else{
    jsonError = true;
    //do nothing 
 
 }    
 
if (numRequests == 0) {
            Ti.API.info('All Requests complete; jsonError is ' + jsonError);
            // all processes complete
            if (jsonError == false) {
                Ti.API.info('Attempting to delete database ' +db);
                db = Ti.Database.open('FrogMan.db');
                db.execute('DELETE FROM GroundStrokeData');
                db.close();
                proof();
                Serve_Data_Tbl();
 
            } else {
 
            }
 
        } 
 }      
 };
 var proof = function(){
    db = Ti.Database.open('FrogMan.db');
    getGroundData = db.execute('SELECT user, MatchUID,Ossys, UserID, SetPrKey, Game, Point, Stroke, XCor, YCor FROM GroundStrokeData');
    numRequests = 0;
    while (getGroundData.isValidRow())
    Ti.API.info('this is database after delete ' +getGroundData);
 
 };

Open in new window

0
Comment
Question by:dolamitejenkins
3 Comments
 
LVL 8

Accepted Solution

by:
Surrano earned 500 total points
ID: 39858507
First off, unless your android device is rooted, adb won't have root access.
Lacking root access you won't be able to read *any* app specific files since each and every app has a different userid assigned and only that user (plus root) can access the file.

If the application is written (or at least can be modified) by you then I recommend adding an export function that exports the entire db content to sdcard.

If you manage to access the sqlite db files, I recommend using the following tool:
http://sqlitebrowser.sourceforge.net/
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now