mardi 30 juin 2015

Is it possible to use SQLite database inside a web application

Since I am new to web application developments, please bear for my silly question.

I am having a scenario wherein the web application want to have a SQLite database inside it.

Also need to access the database with the help of an servlet class/ajax request

I am not sure, its possible or not. please advise me

  1. Is it possible to have a sqlite database inside a application
  2. Id Yes,is it possible to access the same via servlet/ajax request
  3. If yes, is the database will be locally available at client side or not.

Please help me ....!! thanks in advance

useing php while loop json_encode

I am trying to use json_encode() in a while loop while getting database results. Here is my code:

 <?
    $sql_page = "select * from type";
    $rs_type=mysql_query($sql_page,$link);
    while ($row=mysql_fetch_array($rs_type)){
$jsonString =array( "n" => $row['tTitle'],
  "s" => array( array("n" => $row['tTitle1'],
  "s" => array( array("n" => $row['tTitle2'],
 "s" => array( array("n" => $row['tTitle3'],
 "s" => array( array("n" => $row['tTitle4'],
  ),
  ),
  ),
  ),
  ),
  ),
  ),
  ),
);


    $cart = json_encode( $jsonString );
    $file = '../application/js/tecair.json';
    file_put_contents($file, '['.$cart.']');
    ?>

The output following below is

[{"n":"1","s":[{"n":"1_1","s":[{"n":"1_2","s":[{"n":"1_3","s":[{"n":"1_4"}]}]}]}]}]

but i want it to be:

[ { "n":"1", "s":[ { "n":"1_1", "s":[{"n":"1_1_1"},{"n":"1_1_2"},{"n":"1_1_3"},{"n":"1_1_4"}] },{ "n":"1_2", "s":[{"n":"1_2_1"},{"n":"1_2_2"},{"n":"1_2_3"},{"n":"1_2_4"},{"n":"1_2_5"},{"n":"1_2_6"}] },{ "n":"1_3", "s":[ { "n":"1_3_1", "s":[ { "n":"1_3_1_1", "s":[{"n":"1_3_1_1_1"},{"n":"1_3_1_1_2"},{"n":"1_3_1_1_3"},{"n":"1_3_1_1_4"}] } ] } ] },{ "n":"1_4", "s":[{"n":"1_4_1"},{"n":"1_4_2"},{"n":"1_4_3"},{"n":"1_4_4"}] } ] },{ "n":"2" },{ "n":"2_1", "s":[{"n":"2_1_1"},{"n":"2_1_2"},{"n":"2_1_3"},{"n":"2_1_4"},{"n":"2_1_5"},{"n":"2_1_6"}] } ]

How do I use while loop to do it well? thanks!

How to convert MSSQL .sql database file into .sqlite file using PHP

I am working for application which will work offline also, so i have question

How to convert MSSQL .sql database file into .sqlite file using PHP ?

I am not going to use any external converter.

Please suggest

Thanks

Python code running too slow (SQLITE)

I have located a piece of code that runs quite slow (in my opinion) and would liek to know what you guys think. The code in question is as follows and is supposed to:

  • Query a database and get 2 fields, a field and its value
  • Populate the object dictionary with their values

The code is:

query = "SELECT Field, Value FROM metrics " \
        "WHERE Status NOT LIKE '%ERROR%' AND Symbol LIKE '{0}'".format(self.symbol)
query = self.db.run(query, True)
if query is not None:
    for each in query:
        self.metrics[each[0].lower()] = each[1]

The query is run using a db class I created that is very simple:

def run(self, query, onerrorkeeprunning=False):
    # Run query provided and return result
    try:
        con = lite.connect(self.db)

    cur = con.cursor()
    cur.execute(query)
    con.commit()

    runsql = cur.fetchall()
    data = []
    for rows in runsql:
        line = []
        for element in rows:
            line.append(element)
        data.append(line)
    return data

except lite.Error, e:
    if onerrorkeeprunning is True:
            if con:
                con.close()
            return
    else:
        print 'Error %s:' % e.args[0]
        sys.exit(1)

finally:

    if con:
        con.close()

I know there are tons of ways of writting this code and I was trying to keep things simple but for 24 fields this takes 0.03s so if I have 1,000 elements that is 30s and I find it a little too long!

Any help will be much appreciated.

How to Perform Full Text search functionality using MS Entity Framework 6 & sqlite?

I have to implement Full text search functionality using Entity Framework 6.1 with SQLite DB. How to Implement the functionality using C# Linq.

how to get the selected item inside spinner populated from sqlite database

I have written a program to get some values from sqlite database and populate inside spinner ,which is working perfectly , but i want to show the selected item from the spinner into a different activity , all i am getting is either a blank value or android.database.sqlite.SQLiteCursor@3456046c , so how to convert it to string ??

Need some help

int[] to = new int[] { android.R.id.text1 };
    String[] from = new String[] { DbListHelper.ACCOUNT_TYPE };
    final SimpleCursorAdapter adapter4 = new SimpleCursorAdapter(
            getBaseContext(), android.R.layout.simple_list_item_1, cursor,
            from, to) {
        public View getView(int position, View convertView, ViewGroup  
            parent) {
            View v = super.getView(position, convertView, parent);
            ((TextView) v).setTextSize(18);
            ((TextView) v).setGravity(Gravity.CENTER);
            ((TextView) v).setTextColor(Color.parseColor("#1C689C"));
            return v;
        }

    };

    adapter4.setDropDownViewResource
    (android.R.layout.simple_spinner_dropdown_item);
    spinnerType.setAdapter(adapter4);

On button click to save the records i am doing this , acName is the spinner variable which i am inserting , i also tried to put a dummy value inside acName as acName = "1" , which is showing properly .

    btnPrint.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        if(cursor.moveToFirst()){
                            do {
                                acName = 
    cursor.getString(cursor.getColumnIndex(DbListHelper.ACCOUNT_NAME));
                            } while (cursor.moveToNext());

                        }
                        vehicleNo1 = editVehicleNo1.getText().toString();

                        driverName = editDriverName.getText().toString();
                        driverCode = editDriverCode.getText().toString();
                        dieselRate = editDieselRate.getText().toString();
                        dieselQty = editDieselQty.getText().toString();
                        amount = editAmount.getText().toString();
                        referenceNo = editReferenceNo.getText().toString();
                        noOfCopies = editNoOfCopies.getText().toString();
                        remark = editRemark.getText().toString();
                        transactionID = imeiCode + "" + dateTime;

                        if (spinnerData.equals("") || vehicleNo1.equals("")
                                || spinnerAccountName.equals("")
                                || spinnerFuelRate.equals("")
                                || driverName.equals("")
                                || dieselQty.equals("")
                                || dieselRate.equals("")
                                || amount.equals("")
                                || referenceNo.equals("")) {
                            Toast.makeText(getBaseContext(),
                                    "Please fill all the fields",
                                    Toast.LENGTH_LONG).show();
                        }
                        else if (noOfCopies.equals("")) {
                            Toast.makeText(getBaseContext(),
                                    "Please enter any value",
                                    Toast.LENGTH_LONG).show();
                        } else {
                            long id = listHelper.insertPumpData(
                                    acName, vehicleNo1, 
                                    driverName,driverCode,
                                    dieselRate, dieselQty, amount + " Rs",
                                    referenceNo, noOfCopies, date, time,
                                    transactionID);


                        }

                    }
                });

Thank You

SQLite: Can I have a where statement inside another where statement?

I am writing SQL queries in Ruby on Rails application and I will execute these statements in SQLite data base.

Because my queries are composed by other complicated statements, I thought that I can include a where statement inside another where statement.

for example:

SELECT * FROM "patients" INNER JOIN "encounters" INNER JOIN "conditions" WHERE "patients"."patient_characteristic_birthdate" <= '1997-06-30 07:25:50 UTC' AND "encounters"."length_of_stay" <= 120 AND "encounters"."encounter" = 'Inpatient Encounter' AND (SELECT * FROM "patients" INNER JOIN "conditions" WHERE ("conditions"."diagnosis" = 'cancer' OR "conditions"."diagnosis" = 'obesity')))

For this statement, I have the following error: ActiveRecord::StatementInvalid (SQLite3::SQLException: only a single result allowed for a SELECT that is part of an expression: