Friday, March 28, 2014

Get value from sqlite3 db file through javascript

Sqlite3:

For getting values from sqlite3 db through , we will in need of a sql.js file.

Steps for getting values:

1. Include sql.js file in your html file

2. Use following scripts:


<html>
<head>
  <title>
    sql.js
  </title>
  <script src="../js/sql.js"></script>
  <script>
    function readfile(){
      if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.open("GET","path_of_db_file",false);
        xmlhttp.overrideMimeType('text/plain; charset=x-user-defined');
        xmlhttp.send();
        var xmlDoc=xmlhttp.responseText;
        return xmlDoc;
      }

    function bin2Array(bin) {
      'use strict';
      var i, size = bin.length, ary = [];
      for (i = 0; i < size; i++) {
        ary.push(bin.charCodeAt(i) & 0xFF);
      }
      return ary;
    }

    function print(text) {
      var element = document.getElementById('output');
      element.innerHTML = text;
    }

    var dbBin = readfile();
    var db = SQL.open(bin2Array(dbBin));
    function execute() {
      try {
        var data = db.exec('SELECT name FROM projects;');
        var get_value = JSON.stringify(data, null, '  ');
        print(get_value);
      } catch(e) {
        print(e);
      }
    }
  </script>
</head>
<body>
  <input type="submit" value="Get value" onclick="execute()">
  <div id="output"></div>
</body>
</html>

Friday, March 21, 2014

Use of plugin in phonegap

Plugins of Phonegap:

Installation:

There are two method of installation:

1. Through cordova
e.g.
cordova plugin add org.apache.cordova.file
2. Through Phonegap
e.g.
phonegap local plugin add org.apache.cordova.file
also we can use url of github repository instead of org.apache.cordova.file

Use:

For using this we have to make a build before then we can use it. Otherwise it will always show js error or will not include plugins



Thursday, March 13, 2014

Some Commands of Phonegap

Phonegap:

Some useful commands:

sudo npm install -g phonegap   - For install phonegap

phonegap create hello  - For create application

phonegap build  - For build an application in android

phonegap run android  -For run an application in android

phonegap local plugin add https://path_of _plugin  - For install plugin in phonegap

phonegap remote login -u myemail@gmail.com -p mYpASSw0RD  - For remotely login in phonegap

phonegap remote logout  - For remotely logout

phonegap remote run android  - For remotely run android

sudo npm update -g phonegap  - For update phonegap

phonegap version  - For know the version of phonegap

sudo npm install -g phonegap@2.9.0-rc1-0.12.2  - For install specific version of phonegap

Thursday, March 6, 2014

Working on Git

GIT:
Git is a distributed revision control & source code management system. It was initially designed and developed by Linus Torvalds in 2005.

Usefull Commands for GIT:

git branch : For checking the branch name in repository.

git add file_name: For adding file

git commit -m "First Commit": For set the commit

git push origin master: For push the file in master branch

git init: Initializes a git repository

git clone: Makes a Git repository copy from a remote source

git status: Shows you the status of files

git checkout: Checks out a different branch

git merge: Merges one or more branches into your current branch

 git fetch: Fetches all the objects from the remote repository

git pull: Fetches the files from the remote repository

git remote: Shows all the remote versions of your repository