I click Open New Query Tab, But I found that it can not run multiple sql statements?
INSERT INTO ...;
INSERT INTO ...;
INSERT INTO ...;
INSERT INTO ...;
INSERT INTO ...;
it's show message 'INSERT' unexpected
Where is my usage wrong?
Related
I want to send some notification to android app when new row is inserted in table database, but I'm having trouble to check if there is new row inserted or not.
Is there any function or query to check if new row inserted in table? or some logic to acquire that.
It depends on the database you are using.
For example in MySQL you can query the table information_schema.tables to get the latest update time.
https://dev.mysql.com/doc/refman/8.0/en/information-schema-tables-table.html
For postgres
Check if track commit timestamp is on
show track_commit_timestamp;
If it's off, set it to on in your postgresql.conf file and restart postgres.
Post that run the following to track the latest updates in your table
SELECT pg_xact_commit_timestamp(xmin), * FROM YOUR_TABLE_NAME;
i have created dynamic tables in Xamarin forms by using SQLite queries
string cmdStr="CREATE TABLE Mytable ....";
i am able to create table using
SQLiteCommand command = new SQLiteCommand(sqlitConnection);
command.CommandText = cmdStr;
command.ExecuteNonQuery();
the above code is working fine ,i am able to save data to sql lite db
i am unable to get data from db using command.ExecuteQuery() using command string as "select * from Mytable". as seen in screenshot i am unable to fetch content from dynamic tables,please suggest any alternatives
enter image description here
The error message tells you exactly what is wrong - you are not specifying a Type argument T. The correct syntax is
List<T> results = command.ExecuteQuery<T>();
where T is the name of the class you are mapping the results to
I'm attempting to insert data to an SQLite database table and then immediately return the result from a select in the same call, but no data is returned.
Here is the SQL statement:
INSERT INTO Items (Name, DefaultExpirationIntervalId) VALUES ('Item', -1);
SELECT ItemId as '_id', Name, DefaultExpirationIntervalId FROM Items WHERE Name = 'Item';
Here is the code making the SQL call:
Boolean isReadOnly = getSQLiteDatabase().isReadOnly();
// Make sure we can add data to the database
if (!isReadOnly)
{
// Add the item to the database and then use the result to create a new item
Cursor cursor = getSQLiteDatabase().rawQuery(query, null);
if (null != cursor)
{
cursor.moveToFirst();
if (!cursor.isAfterLast())
item = new Item(cursor);
}
}
The rawQuery call returns a cursor (not null), but it is empty.
I verified through ADB that the record was inserted. I've even run this exact query through sqlite3 via the ADB shell and the item was inserted and returned as expected. I have also tried removing the select and retrieving the item in another rawQuery call and that didn't work either.
Does anybody have any idea what might be happening?
I am running this code through a unit test that creates and and destroys the database during every test run.
rawQuery is used ONLY for SELECT statements.
For INSERT, DELETE and UPDATE, you have to use execSQL instead
So, first you must make an INSERT by using execSQL AND THEN use rawQuery for your SELECT.
In case you're asking why...
a SELECT is a QUERY, while INSERT, DELETE and UPDATE are COMMANDS.
I am trying to update a single column in a SQLite database table in my Android project. What I want to do is set the value of "done" column to 1, when the vehicle number is same. I preferred to go with sql queries other than using myDB.update. So I used this query,
update 'details' set done = 1 where vehicle=="*****"
But the problem is, this query is working perfectly in the sqlite databse browser, not in android simulator. This is completely not working at the android simulator. Hope ur advice.
Thanks in advance.
//Declaration
SQLiteDatabase dbx;
ContentValues cv1;
EventDataSQLHelper eventsData;//object of class in which table is created
//on create
eventsData = new EventDataSQLHelper(this);
dbx= eventsData.getReadableDatabase();
cv1 = new ContentValues();
cv1.put("done",1);
//update query
dbx.update("details", cv1, "vehicle=" ? , null);
I am trying to get data in an order by executing rawQuery with join conditions. but i am unable to get expected result.
below is my query.
String queryString = "SELECT DISTINCT B.MakeID , B.Make FROM MakeList B JOIN BodyStyle BS ON B.Makeid = BS.makeid AND BS.Year = 2012 ORDER BY B.Make ASC";
First thing is no need to write ASC coz it is bydefault ascending order to display result so write simple ORDER BY B.Make and second thing specify what you need in results and post database fields also.
Verify that your databases match. You may have db data that your SQLite Manager is accessing that may be different that what is on your Android device. That is probably causing your unexpected behavior.