0

I develop a mobile app and I want to import the contents of a text file inside SQLite db.

I use the below code in order to read text file

function billtxt()
{
    var billjson = '{"posts" : [', 
        i, 
        line = 0,
        bill = 0,
        Amountint,
        Amountdec;

        jQuery.ajaxSetup({
                'beforeSend' : function(xhr) {
                     xhr.overrideMimeType('text/plain; charset=iso-8859-7');
                },
        });

        jQuery.get('Bill.txt',function(data){
            alert(data.length);
            line=0;

            for (i = 1; i <= ((data.length)/156); i += 1) {
                billjson += '{"Id" :' + '"' + data.substr((line+0), 10).trim() + '"'  + ',';
                billjson += '"Code" :' + '"' + data.substr((line+10), 5).trim() + '"'  +  ',';
                billjson += '"Address" :' + '"' + data.substr((line+14), 40).trim() + '"'  +  ',';
                billjson += '"Name" : ' + '"'  + data.substr((line+54), 50).trim() + '"'  +  ',';
                billjson += '"Description" : ' + '"'  + data.substr((line+104), 8).trim() + '"'  +  ',';
                billjson += '"EntrySeason" : ' + '"'  + data.substr((line+112), 23).trim() + '"'  +  ',';
                billjson += '"Period" : ' + '"'  + data.substr((line+135), 11).trim() + '"'  +  ',';
                Amountint = data.substr((line+146), 7).trim();
                Amountdec = data.substr((line+153), 2).trim();
                billjson += '"Revenue" : ' + '"'  + Amountint + '.' + Amountdec + '"'  +  '}';
                line = i * 156;
                if (line == data.length)
                {
                    billjson += ']';
                }
                else 
                {
                    billjson += ',';
                }
            }

            if (line == 0)
            {
                billjson += ']';
            }


            billjson += "}";
            var mybilljson = jQuery.parseJSON( billjson );
        });
}

I convert the reading to JSON but i thing that this is not the appropriate solution...

What have to do for import the reading to SQLite?

2
  • Though I saw a question mark I'm having difficulties seeing the question in here...
    – gdoron
    Sep 20, 2012 at 18:33
  • I just dont know how to import the created json to SQLite
    – kosbou
    Sep 20, 2012 at 18:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.