Showing posts with label SQLite. Show all posts
Showing posts with label SQLite. Show all posts

Friday, April 13, 2012

SQLite plugin for Eclipse



How to browse an Android SQLite Database from Eclipse Kepler

http://www.youtube.com/watch?feature=player_embedded&v=sAvlV0uw5zc

CellObject SQLite Browser : 
http://www.questoid.com/Download.aspx

Questoid website is down and the jar can be downloaded from : 
http://www.java2s.com/Code/Jar/c/com.questoid.htm
http://www.java2s.com/Code/JarDownload/com.questoid/com.questoid.sqlitebrowser_1.2.0.jar.zip

Requirements and how to use CellObject SQLite & XML Browser at
 http://cellobject.net/Tools/CellObjectSQLiteXMLBrowser.aspx

Java Sources at Google Code :
http://code.google.com/p/cellobject/source/browse/

-----------------------------------
How To Install:

Inside the downloaded .zip/.tar file there's a .jar file named net.cellobject.sqlitexmlbrowser_1.2.0.jar. 
Just copy this jar file into the "plugins" folder of your eclipse installation directory, then restart your eclipse.
That's it.








I needed to create an SQLite database for an Android application I was working on. I wanted to browse the database of my application from within Eclipse, instead of pulling it out and browsing with another application.
If you just want to do a little bit of debugging, see if your tables get created the way you want and similar things, there is a very nice plugin for Eclipse that might fit you:
  • Download  the CellObject SQLite & XML Browser plugin.
  • Unzip it
  • Put the .jar file you just extracted inside your eclipse plugin folder (/plugins)
  • restart Eclipse.
  • Start your emulator or plugin in the device on which you installed the application you want to test
  • Open the DDMS perspective in Eclipse (Window —> open perspective —> other —>DDMS)
  • Select your application database (you find it under data/data/[yourapplicationpackage]/databases)
  • Now click on the icon of CellObject browser on the upper right, it will open the CellObject SQLite Browser View.
Instead of Opening DDMS, we can open the CellObject SQLite & XML browser in our Java perspective itself by opening it from Windows--> Show View --> Other --> Other --> CellObject SQLite Browser...

adb shell
sqlite3 /data/data/com.app.name/databases/DatabaseName.db
adb pull /data/data/com.app.name/databases/DatabaseName.db .
sqlite3 DatabaseName.db



Other solution : 
http://www.mysamplecode.com/2011/06/android-emulator-sqlite-database.html
http://sourceforge.net/projects/sqlitebrowser/
http://sqlitebrowser.sourceforge.net/images/slackware9.jpg
http://sourceforge.net/p/sqlitebrowser/svn/73/tree/trunk/src/


Tuesday, October 18, 2011

Create a POST to a REST WCF Service with Fiddler



How to POST to REST WCF web services with Fiddler

CREATE RESTful WCF Service API Using POST: Step By Step Guide

After making a set of REST web services with WCF I tested them by making requests with a browser. 
This is fine for GET requests however you will need some HTTP building tool such as Fiddler to test a POST, PUT or DELETE REST web service.

To begin with I have a WCF REST web service that intends for a RequestData object to be POSTed:

        [WebInvoke(Method = "POST",
            ResponseFormat = WebMessageFormat.Xml,
            RequestFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "auth")]
       ResponseData Auth(RequestData rData);


The definition of RequestData is very simple:



  public class RequestData
    {
        [DataMember]
        public string details { get; set; }
    }


The definition of ResponseData is quite simple:



public class ResponseData
    {
        [DataMember]
        public string Name { get; set; }


        [DataMember]
        public string Age { get; set; }


        [DataMember]
        public string Exp { get; set; }


        [DataMember]
        public string Technology { get; set; }
    }


The function that gets RequestData and returns ResponseData : 


    public ResponseData Auth(RequestData rData)
        {
            var data = rData.details.Split('|');            
           var response = new ResponseData
                               {
                                   Name = data[0],
                                   Age = data[1],
                                   Exp = data[2],
                                   Technology = data[3]
                               };

            return response;
        }


Note this namespace is very important as it will need to be specified in the XML sent in the request. 
Personally I set my DataContract with no namespace to save having to write it out in the XML every time.

Now open up Fiddler and lets get testing:

Create a POST to your REST service in Fiddler
Go to the Request Builder tab in Fiddler.
Set the verb to POST
Set the URL to the one of your service
Type "Content-Type: application/xml" into the Request Headers. 
If you did give your DataContract a namespace other than blank as I did you will need to specify it in the XML of your Request Body. 
Add your XML to the Request Body like : 





The response : 




Comsuming WCF Services With Android

Create a Simple WCF service against Pubs Database using EF, LINQ



PersonPassport4.asmx - Simple webservice : INSERT UPDATE DELETE



RESTful ASP.NET WCF with SQLite without LINQ: 

  [ServiceContract]

    public interface IService1
    {

    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "Notes/{ID}")]
        [OperationContract]
        Note GetNote(string ID);

   [DataContract]
    public class Note
    {
         [DataMember]
        public int ID { get; set; }
        [DataMember]
        public string Category { get; set; }
        [DataMember]
        public string Subject { get; set; }
        [DataMember]
        public string NoteText { get; set; }
    }

      public Note GetNote(string ID)
        {
            string Sql = "SELECT * FROM NOTE WHERE ID=@ID";
            SQLiteCommand cmd = new SQLiteCommand(Sql, conn);
             cmd.Parameters.AddWithValue("@ID", int.Parse(ID));
            SQLiteDataAdapter da = new SQLiteDataAdapter(Sql, conn);
            da.SelectCommand = cmd;
            DataTable dt = new DataTable();
             da.Fill(dt);
            Note note=null;
            if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
                note = new Note();
                note.ID = Convert.ToInt32(row["ID"]);
                note.Category = (string)row["Category"];
                note.Subject = (string)row["Subject"];
                note.NoteText = (string)row["NoteText"];
            }
    
            WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;
             return note;
        }