BTA Flexing

My passion RIAs…………..Shardul Singh Bartwal

Archive for the ‘SQLite’ Category

Working with Sqlite, made easy by using Sqlite Admin

Posted by Shardul Singh Bartwal on February 13, 2011

Sqlite is also having a User Interface to deal with database, Its not necessary to use it by writing the queries only. Simply get the download from link below.Over all User Interface is self explanatory, and provides almost same interface like any other RDBMs.Just download and install it from link below.

Find the link here to download it.

Advertisements

Posted in SQLite | 2 Comments »

Adobe AIR and SQLite Connectivity

Posted by Shardul Singh Bartwal on April 14, 2008

Adobe AIR and SQLite Connectivity

 ===========================

  Abode AIR provides very easy mechanism to connect to the SQLite.I am doing the connectivity by coding. Here nothing different just create the connection and create the SQLConnection,open it, create SQLStatement and execute them, close connection.Upto my experience I think this is the same common way which we used in any database connectivity. So there is nothing special. I found this process very cool especially due the portable size of the SQLite and creating and deleting the database in just one mouse click. Apart form this you don’t require any thing else Flex Builder IDE with AIR. There is no software requirement for the SQLite.

 I am just putting some line of code for your better understanding. You can just copy and paste it. Although Its just a small code but hope it will give you the over all idea about dealing with the database in an AIR application.

 

*************************************************************

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml

layout=”vertical” creationComplete=”init()”

width=”500” height=”400” backgroundColor=”#000000>

<mx:Script>

 

<![CDATA[

      import mx.controls.Alert;

      import mx.collections.ArrayCollection;

      import flash.data.*;

     

      private var ob:Array=new Array();

      public var mysqlConnection:SQLConnection;

      public var _createProdct:SQLStatement;

      public var _insertProduct:SQLStatement;

      public var _selectProduct:SQLStatement;

 

      private const _counterProduct:int = 1;

      private var databaseFile:File =

      File.applicationStorageDirectory.resolvePath(“data.db”);

      private const CREATE_PRODUCT_TABLE:String =

      “CREATE TABLE product (id INTEGER PRIMARY KEY,name TEXT,” +

      “department TEXT, title TEXT, description TEXT);”

     

      private var _id:int;

      private var _name:String;

      private var _department:String;

      private var _title:String;

      private var _description:String;

     

      private var INSERT_PRODUCT:String;

      private const SELECT_PRODUCT:String = “SELECT * FROM product”;

 

      public function createDatabase(databaseFile:File, productCount:int):void

      {

            if ((databaseFile != null) && (databaseFile.exists))

            {

                  databaseFile.deleteFile();

                  dg1.dataProvider=null;

                  Alert.show(“Database Created Successfully.”);

            }

     

            if (productCount < 1)

            {

                  productCount = 1;

            }

     

            mysqlConnection = new SQLConnection();

            mysqlConnection.open(databaseFile, SQLMode.CREATE);

            mysqlConnection.close();

            schemaGeneration();

      }

 

      public function deleteDatabase():void

      {

            if ((databaseFile != null) && (databaseFile.exists))

            {

                  databaseFile.deleteFile();

                  dg1.dataProvider=null;

                  Alert.show(“Database Deleted Successfully.”);

            }

            else

            {

                  Alert.show(“There is no database to Delete.”);

            }

      }

 

      private function schemaGeneration():void

      {

            var sqlStatement:SQLStatement = new SQLStatement();

            mysqlConnection=new SQLConnection();

            sqlStatement.sqlConnection = mysqlConnection;

            mysqlConnection.open(databaseFile, SQLMode.CREATE);

            sqlStatement.text = CREATE_PRODUCT_TABLE;

            sqlStatement.execute();

            mysqlConnection.close();

      }

 

      private function createInsertStatements():void

      {

            if((txt1.text !=“”)&&(txt2.text !=“”)&&(txt3.text !=“”)

            &&(txt4.text !=“”))

            {

                  _id=0;

                  _name=txt1.text;

                  _department=txt2.text;

                  _title=txt3.text;

                  _description=txt4.text;

                 

                  if((databaseFile != null) && (databaseFile.exists))

                  {

                        INSERT_PRODUCT=“INSERT INTO product (id, name, department, title, description)” +

                        ” VALUES (“+“((SELECT max(id) FROM product)+1)”+“,'”+_name+“‘,'”+_department+

                        “‘,'”+_title+“‘,'”+_description+“‘);”;

                        _insertProduct =new SQLStatement();

                        mysqlConnection=new SQLConnection();

                        _insertProduct.sqlConnection= mysqlConnection;

                        mysqlConnection.open(databaseFile, SQLMode.CREATE);

                        _insertProduct.text = INSERT_PRODUCT;

                        _insertProduct.execute();

                        mysqlConnection.close();

                        createSelectStatements();

                        clearAll();

                  }

                  else

                  {

                        Alert.show(“There is no database so please create it First.”);

                  }

            }

            else

            {    

                        Alert.show(“Please enter the proper values For all the relative fields.”);

            }

      }

 

      private function createSelectStatements():void

      {

                  _selectProduct =new SQLStatement();

                  mysqlConnection=new SQLConnection();

                  _selectProduct.sqlConnection = mysqlConnection;

                  mysqlConnection.open(databaseFile,SQLMode.READ);

                  _selectProduct.text = SELECT_PRODUCT;

                  _selectProduct.execute();

                  ob=_selectProduct.getResult().data;

                  mysqlConnection.close();

                  dg1.dataProvider=ob;

      }

 

      private function clearAll():void

      {

                  txt1.text=“”;

                  txt2.text=“”;

                  txt3.text=“”;

                  txt4.text=“”;

      }

]]>

 

</mx:Script>

 

<mx:VBox width=”100%” height=”100%” horizontalAlign=”center>

     

      <mx:HBox width=”80%” height=”30” horizontalAlign=”center>

     

            <mx:Label width=”120” textAlign=”right” text=”Name” color=”#ff0000/>

           

            <mx:TextInput id=”txt1” width=”120” height=”35/>

 

      </mx:HBox>

 

      <mx:HBox width=”80%” height=”30” horizontalAlign=”center>

     

            <mx:Label width=”120” textAlign=”right” text=”Department” color=”#ff0000/>

           

            <mx:TextInput id=”txt2” width=”120” height=”35/>

     

      </mx:HBox>

 

      <mx:HBox width=”80%” height=”30” horizontalAlign=”center>

     

            <mx:Label width=”120” textAlign=”right” text=”Title” color=”#ff0000/>

           

            <mx:TextInput id=”txt3” width=”120” height=”35/>

     

      </mx:HBox>

 

      <mx:HBox width=”80%” height=”30” horizontalAlign=”center>

     

            <mx:Label width=”120” textAlign=”right” text=”Description” color=”#ff0000/>

           

            <mx:TextInput id=”txt4” width=”120” height=”35/>

     

      </mx:HBox>

     

      <mx:HBox width=”80%” height=”100%” horizontalAlign=”center>

     

            <mx:DataGrid id=”dg1” width=”100%” height=”100%>

           

                  <mx:columns>

           

                        <mx:DataGridColumn id=”idCol” width=”50” dataField=”id” headerText=”Id” textAlign=”center/>

                       

                        <mx:DataGridColumn id=”nameCol” width=”100” dataField=”name

                              headerText=”Name” textAlign=”center/>

                       

                        <mx:DataGridColumn id=”departmentCol” width=”100” dataField=”department

                              headerText=”Department” textAlign=”center/>

                       

                        <mx:DataGridColumn id=”titleCol” width=”100” dataField=”title

                              headerText=”Title” textAlign=”center/>

                       

                        <mx:DataGridColumn id=”descriptionCol” width=”200” dataField=”description

                              headerText=”Description” textAlign=”center/>

           

                  </mx:columns>

           

            </mx:DataGrid>

     

      </mx:HBox>

     

      <mx:HBox width=”80%” height=”50” horizontalAlign=”center>

     

            <mx:Button id=”btnCreateDataBase” label=”Create DataBase” width=”130

                  click=”createDatabase(databaseFile,_counterProduct)”/>

           

            <mx:Button id=”btnInsertIntoDataBase” label=”Insert into DataBase” width=”150

                  click=”createInsertStatements()”/>

            <mx:Button id=”btnDeleteDataBase” label=”Delete DataBase” width=”130

                  click=”deleteDatabase()”/>

      </mx:HBox> 

</mx:VBox>

 </mx:WindowedApplication>

  

********************************************************** 

Hope you will enjoy this………………………………….. 

 

Posted in AIR, SQLite | 21 Comments »

What and Why SQLite?

Posted by Shardul Singh Bartwal on April 13, 2008

What and Why SQLite?

====================

As all of us know that the database is the vital element for the development of any application. If any one will tell that there is no concept of any application without database than I think he will absolutely right. But Is it feasible to go for the databases specially in the cases when our requirement is not related to the vast amount of data. Is there any way for dealing with the applications which require the small size database and what is the solution for the cases when we are working with the electronic devices like PDAs, mobile phone etc.What should be the substitute for the database in such cases.

  What about the idea if you don’t require installing any database for using data in your application. How amazing will be the way if there will only a single file which will be storing all the data in it. And how amazing it will be if we can send this file with our application’s deployment. What about the idea if we can use the SQL for dealing with this kind of the database. This all looks impossible initially. But this all can be achieved by just using the SQLite.SQLite full fill all above scenario.Beacause it’s search engine is smaller than any other database search engine.There is no requirement of any kind of the installation so there is no question of any particular server. It is used with cellular phone, PDAs and many other electronic devices, wherever there is requirement of storing data without any bulky database. It is totally transactional database. Transaction database means which full fill the ACID properties. Here ACID refers to Atomicity, Consistency, Isolated, and Durability.

 At last the summary is that the SQLite is the smallest database engine, and you can use it in the same way as any other database. In your application writing the sql queary, creating the database connection etc can be used in the traditional way.

 

 

Hope you will enjoy its implementation………………….

 

Posted in SQLite | 2 Comments »