Android SQLite, some SQL basics
-
27-10-2019 - |
سؤال
I am following this tutorial: http://www.codeproject.com/KB/android/AndroidSQLite.aspx
I must be overthinking this SQLite stuff (in the past my domain server would automatically initialize databases I requested, and I could do queries when desired. never put one together from scratch)
I have some questions about their onCreate function. I never recall using a
CREATE TRIGGER
command in my SQL
I only need to create one table with 2 or 3 columns (if you count the primary key)
I should just be able to do
db.execSQL("CREATE TABLE" + tableName +"("+colID+"INTEGER PRIMARY KEY,"+columnName+"TEXT)");
correct?
Do I need a "Trigger" and a "View" ?
المحلول
If you just need a place to store some data - then Table is enough. But if your logic is more complicated then you'll need additional stuff.
Also note that some Triggers are not supported by SQLite: Info from here
نصائح أخرى
You not need to create TRIGGER. Unless it is required. Here is how I implemented in one of my project. Hope this help.
https://github.com/gopalB/FeedReader/blob/master/src/com/feedReader/provider/FeedDB.java
if SQLite TRIGGER
and VIEW
are similar to what they're used for in MySQL then no, they are not necessarily for what you're trying to accomplish.
VIEW
s are useful when you have complex queries (like when using JOIN
s to join data from multiple tables).
TRIGGERS
s are conditions that are run when you modify a table. (like using UPDATE
, or INSERT
)
As written, your create statement won't work because of a lack of whitespace. Try:
db.execSQL("CREATE TABLE " + tableName +" (" + colID + " INTEGER PRIMARY KEY, " + columnName + " TEXT)");