I successfully attached DB to another DB using SQLCipher like this:
ATTACH DATABASE '/storage/emulated/0/Android/data/testApp/files/dbTest1.s3db'
AS dbTest1 KEY 'Password';
I am not getting any error. When I try to use this query:
SELECT column1, column2, column3 FROM dbTest1.SaTTest
UNION SELECT column1,column2,column3 FROM SatTest
WHERE (Address1 LIKE '%cor%' OR column1 LIKE '%cor%')
I am getting this error:
I/Database(2587): sqlite returned:
error code = 1, msg = no such table: dbTest1.SaTTest.
How can i use alias in attached database tables?
I believe it's just a typo, it should be dbTest1.SatTest instead of dbTest1.SaTTest. Please always keep in mind case-sensivity
Related
My SQLLite query is not working properly. See below:
UUID i=UUID.randomUUID();
String Beregero ="INSERT INTO
contacts(id,uuid,name,phone,email,street,city,state,zip) " +
" VALUES(3,"+"'"+i.toString()+"'"+",'Patrice
Beregeron','978-555-1212','pBeregero#BostonBruins.com'," +
"'1 causeway street','Boston','Mass','01236');";
db.execSQL(Beregero);
I am receiving the following error in my log:
(table contacts has no column named uuid (code 1): , while
compiling: INSERT INTO contacts(id,uuid,name,phone,email,
street,city,state,zip) VALUES(3,'12ee5bbf-dabb-4d95-bfe7-6e6f14702add',
'Patrice Beregeron','978-555-1212','pBeregero#BostonBruins.com',
'1 causeway street','Boston','Mass','01236');)
#################################################################
The exception says it all, your table has no column name uuid created. So uninstall the app, then run it again. This error occurs only if the column is not generated.
The error message in you log clearly states the problem. The contacts table does not have a column uuid. You now could do the following:
Check if you have got right lower case vs. upper case. The column in question might be UUID instead of uuid (I don't know SQLite, but case matters in many database systems).
If the column really is not in the table yet, then add it (either by code or by hand). Read SQLite's documentation to learn how to that (I can't help you here because I don't know SQLite).
Uninstalling and re-installing the app would help only if the app would generate the database upon installing or during the first run. Since we don't know anything about the app, this might or might not be the case.
You have not added the column "uuid" in the create table "contacts" query like this :
String createTableContacts = "create table contacts ( ' uuid text ')";
I want to add sqlite in my application i have created DB and table but the SELECT and INSERT query is not working i Don't know why?
Here i have added my code:
static Cursor c;
SQLiteDatabase db;
db=openOrCreateDatabase("weatherregisterDB", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS weatherRegister(id INTEGER PRIMARY KEY AUTOINCREMENT,name VARCHAR,username VARCHAR,password VARCHAR,confirmpassword VARCHAR);");
register.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
db.execSQL("INSERT INTO weatherRegister(id,name,username,password,confirmpassword) VALUES('',sample,sample,sample,sample);");
c=db.rawQuery("SELECT username FROM weatherRegister WHERE username=sample", null);
My Error is:
android.database.sqlite.SQLiteException: no such column: sample (code 1): , while compiling: INSERT INTO weatherRegister(id,name,username,password,confirmpassword) VALUES('',sample,sample,sample,sample);
could you provide the error ?
but at first look this line
db.execSQL("INSERT INTO weatherRegister(id,name,username,password,confirmpassword) VALUES('',sample,sample,sample,sample);");
should be :
db.execSQL("INSERT INTO weatherRegister(id,name,username,password,confirmpassword) VALUES('sample','sample','sample','sample');");
you don't have to wire ('') for (id) if it's auto increment , also (String) values should be between ('')
and the same for the select query
Original :
SELECT username FROM weatherRegister WHERE username=sample
Update to :
SELECT username FROM weatherRegister WHERE username='sample'
hope that will help before you show us the error.
Ahmad Okaily's answer is correct. One more thing is you don't need to write _id in your insert statement since it's auto-increment.
I've tried it in SQLite command line and seems it's working fine.
Can't give you an Android code version because my PC in company is too slow for eclipse or android studio.
SQLite version 3.8.7.4 2014-12-09 01:34:36
Enter ".help" for usage hints.
sqlite> INSERT INTO weatherRegister(id,name,username,password,confirmpassword) VALUES('sample','sample','sample','sample');
Error: 4 values for 5 columns
sqlite> INSERT INTO weatherRegister(name,username,password,confirmpassword) VALUES('sample','sample','sample','sample');
sqlite> select * from weatherRegister;
1|sample|sample|sample|sample
sqlite>
Try changing this line
c=db.rawQuery("SELECT username FROM weatherRegister WHERE username=sample", null);
to
c=db.rawQuery("SELECT username FROM weatherRegister WHERE username='sample'", null);
Please note single inverted comma near "sample".Hope it will help.Thanks.
Instead of using the VARCHAR data type use TEXT as the datatype for your attributes.
I am making an Android app that get the data from URL stores it in to the database (I am done till this stage) and use some of the field of that table.
I tried to fetch the specific data using this SQL query
"select persons_name where persons_name=s"
but there was an error
I/Database(23722): sqlite returned: error code = 1, msg = near "FROM": syntax error
you have to specify in which table the data is located.
The correct SQL is:
select persons_name FROM Persons where persons_name=s
assuming the table is Persons
This will be select all names who have name starting letter is 's'
"SELECT persons_name FROM persons WHERE persons_name LIKE 's%'
As pointed out by #JesusS, try this:
"SELECT persons_name FROM persons WHERE persons_name LIKE 's'"
I needed to store some data related to class periods in an Android project. After looking at my options, I thought a SQL database would be a good choice. Unfortunately, I can't seem to get my statement to actually open a database. My open database statement string goes like this:
"create table "+ DATABASE_PERIOD+" (_id integer primary key autoincrement,"
+KEY_CLASSTITLE+" text not null, "+KEY_PERIOD+" text not null,
"+KEY_XPERIODS+" text not null, "+KEY_DOUBLEPERIODS+" text not null);
I based it off of the Notepad project on the Android website. I just added a few more fields, but it is unable to open the database. If you guys want the error message or some other kind of info, I'll try to get it for you (This is my first time with SQL so I don't really know what is needed to fix this up). Thanks in advance!
The error message I'm getting goes like this:
android.database.sqlite.SQLiteException: no such table: periodData: , while
compiling: SELECT DISTINCT _id, title, period, xPeriods, doublePeriods FROM
periodData WHERE _id = -1
And as it says there, I'm using SQLite.
My code to put some data into the table in my Database Helper class:
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_CLASSTITLE, title);
initialValues.put(KEY_PERIOD, period);
initialValues.put(KEY_XPERIODS, xPeriods);
initialValues.put(KEY_DOUBLEPERIODS, doublePeriods);
return mDb.insert(DATABASE_PERIOD, null, initialValues);
I started using private static strings to ensure that my calls aren't incorrect (Thanks Barak for the catch!)
Your issue is the table name (as the error message indicates). From the code you show you created a table called "period". Yet you try to query it using the table name "periodData".
Two ways to fix it:
1) Change the table name in your database to periodData (more difficult as it involves re-creating the db).
2) Change the table name in your query from "periodData" to "period".
Check out the dev topic on http://developer.android.com/guide/topics/data/data-storage.html#db
You'll create a DbHelper class to help you open the database and your code will look something like:
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);
Hope this was helpful.
Suppose I have two database files a.sqlite and other one is b.sqlite. suppose table1 is in a.sqlite and table2 in b.sqlite. I open a.sqlite in read-only mode and b.sqlite in read-write.Suppose both table table1 and table2 has same column name "description".table2 has description column with all null values and table1 has some values.So how can i add the data from table1 into table2.I know through query.But as these r in two different databse,so is there ant problem? Can any one suggest ?
Not sure if your environment allows it, but ATTACH DATABASE is normally the way to go:
http://www.sqlite.org/lang_attach.html