Affichage des articles dont le libellé est database. Afficher tous les articles
Affichage des articles dont le libellé est database. Afficher tous les articles

lundi 24 mars 2014

[Q] Store and Send data automatically Using SQLite Database topic




Hi my app will do wifi scan and send the data (using JSON Array) to splunk server(web server) periodically, now at the time of wifi disconnection I cant send, so I am planning to store the scan result using SQLite database and automatically send them to server when it reconnect to the wifi network. Kindly help me how to do that.

FYI: when the user is disconnected the app will scan and store data for every 1 min and when reconnect it should send automatically the stored data to the server.

I can start the scan when disconnection happens but dont know how to store the data in JSON format in SQLite and send them automatically to server without getting request form the server.

Thanks in Advance





dimanche 16 mars 2014

[Q] app with database? topic




Ok so im familiar with eclipse and unity and such, but my company which is an oil field company asked me to make an app for them. I have made guide type apps as well as a cpl games but what they want is something I have never done. What they want is an app that the employees can put in data from the field reports like well head pressures gas rates etc.. This app will require multiple tabs for seperator, well heads, readings, as well as data for equipment worked on. They also wamt to make it to wjere the app will allow an administrative log in and employee log in. Where the admin can add or delete data.. the employee can only add. This all sound fairly simple with the design but how do I get it to wjere this info is shared with multiple employees from the same database. Any info is greatly appreciated.





samedi 8 mars 2014

[Q] How to fix corrupt database? topic




Hello,

When I try to recover my Whatsapp messages on my new phone after I have copied the Whatsapp folder from my old phone to the SDcard, it suddenly crashes after 10 seconds: "Whatsapp has stopped working" :eek:

I looked into the System Log to find some clues about this crash. It looks like it has something to do with SQLite and the msgstore.db (or msgstore.db.crypt) file which says that the msgstore.db file is corrupt.

Can somebody help me to unravel this mistery? :confused: I really want to copy my old messages to my new phone and continue using the app on my new phone.

How can I fix the corrupt msgstore file? Or see what part of the file is corrupt (the exact cause)

NOTE: I added some screenshots of the System Log file to give you more information








Attached Thumbnails


Click image for larger version<br/><br/>Name:	Screenshot_2014-03-07-20-19-09.jpg<br/>Views:	N/A<br/>Size:	208.9 KB<br/>ID:	2619943
 

Click image for larger version<br/><br/>Name:	Screenshot_2014-03-07-20-25-53.jpg<br/>Views:	N/A<br/>Size:	213.6 KB<br/>ID:	2619944
 

Click image for larger version<br/><br/>Name:	Screenshot_2014-03-07-20-26-24.jpg<br/>Views:	N/A<br/>Size:	211.5 KB<br/>ID:	2619946
 

Click image for larger version<br/><br/>Name:	Screenshot_2014-03-07-20-27-42.jpg<br/>Views:	N/A<br/>Size:	207.1 KB<br/>ID:	2619947
 
















vendredi 7 mars 2014

[Q] [WHATSAPP] Unable to recover message history: Corrupt Database topic




Hello,

Whatsapp problem! I want to copy my chat history from my Samsung Galaxy S1 (2.3.6) to my new Nexus 5 (4.4.2).

I copied my entire Whatsapp folder to my Nexus 5 (/sdcard/Whatsapp/) and then installed Whatsapp. It asked me if I would like to recover my history chat messages. After clicking yes it started recovering but after 10-20 seconds it shuts down and an error message comes forward saying that Whatsapp had stopped working. I tried it multiple times.

When looking in my System Log file it says that it has something to do with SQLite. These are some lines in the Log file concerning Whatsapp:
  1. "E/DefaultDatabaseErrorHandler (3784): Corruption reported by sqlite on database: /data/data/com.whatsapp/databasesmsgstore.db"

  2. "E/AndroidRuntime (3784): java.lang.AssertionError: android.database.sqlite.SQLiteDatabaseCorruptExcep tion: Database disk image is malformed (code 11), SQLiteConnection.java,-2"

  3. "E/SQLiteLog (3784): (14) cannot open file at line 30191 of [00bb9c9ce4]"

  4. "E/SQLiteDatabase (3784): Failed to open database '/data/data/com.whatsapp/databases/msgstore.db' "

  5. "E/SQLiteDatabaseException: unknown error (code 14): Could not open database"

  6. "I/sqlite_db_corrupt (3784): /data/data.com.whatsapp/databases/msgstore.db"

:confused:
Can someone tell me how to fix this problem or how to find what the error causes in my database file? :crying:

NOTE: I added screenshots of System Log














Attached Files





File Type: zip sqlitecorrupt.zip -
[Click for QR Code]
(2.60 MB)









[Q] [WHATSAPP] Unable to recover message history: Corrupt Database topic




Hello,

Whatsapp problem! I want to copy my chat history from my Samsung Galaxy S1 (2.3.6) to my new Nexus 5 (4.4.2).

I copied my entire Whatsapp folder to my Nexus 5 (/sdcard/Whatsapp/) and then installed Whatsapp. It asked me if I would like to recover my history chat messages. After clicking yes it started recovering but after 10-20 seconds it shuts down and an error message comes forward saying that Whatsapp had stopped working. I tried it multiple times.

When looking in my System Log file it says that it has something to do with SQLite. These are some lines in the Log file concerning Whatsapp:
  1. "E/DefaultDatabaseErrorHandler (3784): Corruption reported by sqlite on database: /data/data/com.whatsapp/databasesmsgstore.db"

  2. "E/AndroidRuntime (3784): java.lang.AssertionError: android.database.sqlite.SQLiteDatabaseCorruptExcep tion: Database disk image is malformed (code 11), SQLiteConnection.java,-2"

  3. "E/SQLiteLog (3784): (14) cannot open file at line 30191 of [00bb9c9ce4]"

  4. "E/SQLiteDatabase (3784): Failed to open database '/data/data/com.whatsapp/databases/msgstore.db' "

  5. "E/SQLiteDatabaseException: unknown error (code 14): Could not open database"

  6. "I/sqlite_db_corrupt (3784): /data/data.com.whatsapp/databases/msgstore.db"

:confused:
Can someone tell me how to fix this problem or how to find what the error causes in my database file? :crying:

NOTE: I added screenshots of System Log





dimanche 23 février 2014

[Q] app slow down when using sqlite database topic




I am trying to create a circular buffer using sqlite. For some reason every time I instantiate my db access class, the os start skipping frames (I am using the emulator to run my code).

02-22 20:22:03.172: I/Choreographer(860): Skipped 628 frames! The application may be doing too much work on its main thread.

I do not understand what I am doing wrong. I am calling the database class from an intentService (I assume this should not slow down the main thread at all) as follows:

Code:


private SqliteLog mSqliteLog;
mSqliteLog = new SqliteLog(context);
mSqliteLog.writelogInformation("sleepMode", "ON");


I added my code at the end of this message

Code:


/**
 * SqliteLog
 *
 *
 * Base class for sqliteLog control
 *
 *
 */
public class SqliteLog {

    // Debug log tag
    private static final String tag = "SqliteLog";

    // Version of database
    private static final int DATABASE_VERSION = 1;

    // Name of database
    private static final String DATABASE_NAME = "log";

    // Table of database
    private static final String TABLE_NAME = "log";

    public static final String ROWID_NAME = "id";
    public static final String PREFERENCE_NAME = tag + "Pref";

    public static final String COLUMN_LOGNUMBER = "logNumber";
    public static final String COLUMN_TIME = "time";
    public static final String COLUMN_FUNCTION = "function";
    public static final String COLUMN_DESCRIPTION = "description";
    public static final int TABLE_SIZE = 20;

    private static final String DATABASE_CREATE ="create table " + TABLE_NAME + " (" + ROWID_NAME + " integer primary key autoincrement, " +
                                                                                    COLUMN_LOGNUMBER + " INTEGER NOT NULL, " +
                                                                                    COLUMN_TIME + " TEXT NOT NULL, " +
                                                                                    COLUMN_FUNCTION + " TEXT NOT NULL, " +
                                                                                    COLUMN_DESCRIPTION + " TEXT NOT NULL " +
                                                                                  ");";

    //The context of the calling class;
    private Context thisContext;

    /**
    * <p>Constructor for SqliteLog
    * @param context :- Context of calling class
    *
    */
    public SqliteLog(Context context) {
        Log.d(tag,"SqliteLog constructor called");

        thisContext = context;
    }

    /**
    * writelogInformation :- Writes a row into the log table
    *
    */
    public void writelogInformation(String functionName, String descriptionInfo) {
        // Retrieve preferences
        SharedPreferences SqliteLogPref = thisContext.getSharedPreferences(PREFERENCE_NAME,  Context.MODE_PRIVATE);
        int logNumber = SqliteLogPref.getInt("logNumber", 1);

        // Open database for writing
        DatabaseHelper databaseHelper = new DatabaseHelper(thisContext);
        SQLiteDatabase sQLiteDatabase = databaseHelper.getWritableDatabase();

        // Define the column name and data
        ContentValues values = new ContentValues();
        values.put(COLUMN_LOGNUMBER, logNumber);
        values.put(COLUMN_TIME, getTime());
        values.put(COLUMN_FUNCTION, functionName);
        values.put(COLUMN_DESCRIPTION, descriptionInfo);

        // Update database
        sQLiteDatabase.update(TABLE_NAME, values, null, null);

        // Close database
        databaseHelper.close();

        // Test if next database update will need to be wrapped around
        logNumber = (logNumber % TABLE_SIZE) + 1;

        // Store preferences
        SharedPreferences.Editor editor = SqliteLogPref.edit();
        editor.putInt("logNumber", logNumber);
        editor.commit();
    }

    /**
    * clearLog :- Erase all information from table
    *
    */
    public void clearLog() {
        // Retrieve preferences
        SharedPreferences SqliteLogPref = thisContext.getSharedPreferences(PREFERENCE_NAME, 0);

        // Store preferences
        SharedPreferences.Editor editor = SqliteLogPref.edit();
        editor.putInt("logNumber", 1);
        editor.commit();

        // Delete all rows
        DatabaseHelper databaseHelper = new DatabaseHelper(thisContext);
        SQLiteDatabase sQLiteDatabase = databaseHelper.getReadableDatabase();
        sQLiteDatabase.delete (TABLE_NAME, null, null);
    }

    /**
    * readlogInformation :- Read the whole table
    *
    */
    public String[] readlogInformation() {
        // Create string array of appropriate length
        String[] returnArray;

        // Retrieve preferences
        SharedPreferences SqliteLogPref = thisContext.getSharedPreferences(PREFERENCE_NAME, 0);
        int logNumber = SqliteLogPref.getInt("logNumber", 0);

        // Open database for reading
        DatabaseHelper databaseHelper = new DatabaseHelper(thisContext);

        try {
            SQLiteDatabase sQLiteDatabase = databaseHelper.getReadableDatabase();

            // Get a cursor to the correct cell
            Cursor cursor = sQLiteDatabase.query(TABLE_NAME, null, null, null, null, null, null);

            // Get number of rows in table
            int lengthOfTable = 0;

            // Move cursor to where it needs to be
            if (cursor != null) {
                lengthOfTable = cursor.getCount();

                // If count is less than max, then we have not wrapped around yet
                if(lengthOfTable < TABLE_SIZE) {
                    cursor.moveToFirst();
                }

                // Position cursor appropriately
                else {
                    cursor.moveToPosition(logNumber-1);

                }

                // Create string array of appropriate length
                returnArray = new String[lengthOfTable];

                for(int i=1; i<=lengthOfTable; i++) {

                    returnArray[i] = cursor.getString(1) + "; " + cursor.getString(2) + "; " + cursor.getString(3);
                }
            }
            else {
                Log.e(tag,"Cursor null");

                // Create string array of appropriate length
                returnArray = new String[0];
            }
        } catch(SQLiteException e) {
            Log.d(tag,"SQLiteException when using getReadableDatabase");

            // Create string array of appropriate length
            returnArray = new String[0];

        }


        // Close database
        databaseHelper.close();

        return returnArray;
    }

    /**
    * readlogInformation :- Read the whole table
    *
    */
    public String getTime() {
        // Create a new time object
        Time currentTime = new Time(Time.getCurrentTimezone());

        // Get current time
        currentTime.setToNow();

        return currentTime.toString();
    }


    /**
    * DatabaseHelper
    *
    *
    * Class to help control database
    *
    *
    */
    private static class DatabaseHelper extends SQLiteOpenHelper {
        /**
        * <p>Constructor for DatabaseHelper
        * @param context :- Context of calling class<p>
        *
        */
        DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);

            Log.d(tag,"DatabaseHelper constructor called");
        }

        /**
        * <p>onCreate
        * @param db :- Pass an sqlite object
        *
        */
        @Override
        public void onCreate(SQLiteDatabase db) {
            Log.d(tag,"onCreate called");

            // Create database
            db.execSQL(DATABASE_CREATE);

            // Insert a new row
            ContentValues values = new ContentValues();

            // Create a certain number of rows
            for(int i=1; i<=TABLE_SIZE; i++) { 
                values.clear();
                values.put(COLUMN_LOGNUMBER, i);
                values.put(COLUMN_FUNCTION, "empty");
                values.put(COLUMN_DESCRIPTION, "empty");
                db.insert(TABLE_NAME, "null", values);         
            }

            Log.d(tag,"database created");
        }

        /**
        * <p>onUpgrade
        * @param db :- Pass an sqlite object
        * @param oldVersion :- Old version of table
        * @param newVersion :- New version of table
        *
        */
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.d(tag,"onUpgrade called");

            // Not used, but you could upgrade the database with ALTER
            // Scripts
        }
    }
}


I have been trying to figure this out for a while now. I would appreciate any insight, Amish





samedi 25 janvier 2014

Re: Pls help me...I want to save data to my database but I am unableto topic




On Sun, Jan 26, 2014 at 6:00 AM, Max Cuban <(E-Mail Removed)> wrote:
> This is my first programming pet project. I have the following script that
> extracts links from specific sites and display them on the web(via django).
> The script work fine but I'm unable to save any stuff in my database.
>
> Hence if I run the code, I get the output I want but then it always extracts
> only new content. I will rather want to have the content scrapped earlier
> saved to the database so that on subsequent run, it only scrap and append
> ONLY new links to the list.


At what point are you saving anything to the database? I'm not seeing
it. This may be a consequence of there being simply too much code for
the post - when you have a problem, try to post the smallest amount of
code necessary to demonstrate that problem. If your problem is saving
stuff to the database, create a project that simulates generating
links (maybe just hard-codes a dozen of them), and tries to save them.
Often, the exercise of making the small version actually shows you
where the problem is, right there; and if it doesn't, it's much easier
for us to see and help you. In this case, after reading your opening
paragraph, the very first thing I did was to scan your code for a
"commit" operation - but I couldn't find one, and I can't find any
database work.

BTW, the word you want here is "scrape" (other tenses "scraping" and
"scraped"). Scrapping ("scrap", "scrapped" - pronounced with a short
'a' sound like "flapping") is destruction and disposal - "the wreckers
are scrapping hundreds of smashed cars". Scraping (pronounced with a
long 'a' sound like "trading" [1]) is running a tool over something to
clean something else off - "every winter, car owners spend innumerable
hours scraping ice off their windscreens" - and this is the word
that's been picked up for "screen scraping" and related terms.

Hope that helps!

ChrisA

[1] I could go into detail about single and double consonants if
anyone's curious, but I don't think it'd help)