somancy
somancy

Reputation: 1

How to implement file operations with QT and SQLite

Greetz,

I'm very curious on how to use basic file operations within QT and SQLite and wondering if there are current examples. My ideas are things like;

or something like

Any help with this would be more than appreciated, thx.

Upvotes: 0

Views: 338

Answers (2)

Marina Agarwal
Marina Agarwal

Reputation: 11

dbAdapter example if you want to save Logs per se.

public class DBAdapter {
    static final String ________________ (xtimes u need it)

    static final String DATABASE_CREATE = "CREATE TABLE ('_______');
    final Context context;
    DatabaseHelper DBHelper;
    SQLiteDatabase db;

    public DBAdapter(Context ctx)
    {
        this.context = ctx;
        DBHelper = new DatabaseHelper(context);
    }
    private static class DatabaseHelper extends SQLiteOpenHelper
    {
        DatabaseHelper(Context context)
        {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
        @Override
        public void onCreate(SQLiteDatabase db)
        {
            try {
                db.execSQL(DATABASE_CREATE);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
        {
            Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS vehicle");
            onCreate(db);
        }
    }

    public DBAdapter open() throws SQLException
    {
        db = DBHelper.getWritableDatabase();
        return this;
    }

    public void close()
    {
        DBHelper.close();
    }

    public long insertVehicle(String _________ (xtimes u want))
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(_________);
        return db.insert(DATABASE_TABLE, null, initialValues);
    }

    public Cursor getAllVehicles()
    {
        return db.query(DATABASE_TABLE, new String[] {DATABASE_ROW_ID, ____}, null, null, null, null, null);
    }

Upvotes: 1

ScarCode
ScarCode

Reputation: 3094

Qt already has MySql as a built in SQL package for database operations. QSQllite may not be available due to license incompatibilities. If you want to use sqllite, you should install development package for using sqllite services.

Operations like u mentioned are absolutely doable with sqllite.

You can find sqllite examples at http://doc.trolltech.com/4.5/examples.html#sql

Upvotes: 0

Related Questions