Square Brackets and Quotation Marks in SQL [duplicate] - android

This question already has answers here:
What does the SQL Standard say about usage of backtick(`)?
(2 answers)
Closed 7 years ago.
I'm new to SQL.
In fact, I just started to use SQLite for Android.
I saw some SQLite examples and found some people using "" and [].
I tested those in my code and now I'm guessing they are just the same as ``.
1. Am I right?
2. If so, those are standard? I mean, can I use them in MySQL or Oracle too?
I also tried "" instead of '' for column data and worked fine.
3. Can I use double quotation marks for this use case? And standard?

The SQL standard to encapsulate strings is '', on ALL RDBMS platforms.
[ and ] are used to escape spaces in columns (or indexes) or table (or view) names.

Related

How to query firebase database for contains clause [duplicate]

This question already has answers here:
Query based on multiple where clauses in Firebase
(8 answers)
Closed 2 years ago.
I want to query firebase database with name contains the search text, In Android.
My database structure is shown in image.
I want to query first name and last name and get limited records in result.
One way that you can get around this problem is to concatenate first name and last name into a new couple. Something like this: First_Last_Name: "Rahul_Rajesh". Just be noticed that this way causes redundancy and you should avoid it unless you REALLY need it.

List of special characters that not work in sqlite query? [duplicate]

This question already has an answer here:
SQLite: Escaping Special Characters
(1 answer)
Closed 6 years ago.
how can find a list of special characters that should not use in sqlite query or using that(') giving me exception like this
android.database.sqlite.SQLiteException: near "name": syntax error
(code 1)
Please refer the following links. It is a possible duplicate.
Sql query with special characters - how to handle?
http://www.orafaq.com/faq/how_does_one_escape_special_characters_when_writing_sql_queries

Is it a good idea to fill a database using a .txt? [duplicate]

This question already has answers here:
Ship an application with a database
(15 answers)
Closed 7 years ago.
I am currently learning how to use database in Android. For one of my app, I need to stock 500 string values in order to read them.
Actually to fill my database, I read a .txt file at the database creation with all the string values inside. For each lines of .txt (corresponding to a string value), I create a new data in the database. The thing is I know that accessing a file can be long it is not a very good thing if there are thousands of values.
According to that, I have two questions :
Is it really usefull to create a database ? (because I can directly access the string values by reading the .txt)
Is there a better way to fill the database ? Or a way to create a database already filled before the activity creation ? (because currently, each time you close the activity you close the database and each time you reopen it, it recreate and refill the database.)
How about instead of having .txt have a .csv file with values and use org.apache.commons.csv or super csv for parsing the csv file. I haven't used super csv but it provides support for POJO support which i think can be really handy. This will increase your performance and parsing speed. But it would be based on your situation. i would recommend creating a database if you need to perform SQL queries on your data for eg. joins or nested queries. If you just need to display you can use a CSV file.

Using android with existing SQLite [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to ship an Android application with a database?
I'm trying to develop an app that needs to read data from a database and display it to the user. Perhaps in the future I could add an option for users to leave comments on various articles, for which I'll need a server instead of SQLite right?
But for reading data is it better to have a local database with 3k to 5k records in each table?
Secondly I'm a total newbie when it comes to Android and databases. I've dealt with PHP+MySQL but it's not quite the same. Since the records are a lot, I'd like to enter them from a back-end (sqlitebrowser) and copy the file from assets folder (done this already). I've tried creating a database helper class using tutorials online but that didn't work at all for me. I also tried creating a connection profile in Eclipse which kinda works when I tried using the SQL Scrapbook view. It doesn't give errors, but select query doesn't show anything in SQL Results
Remember I do not want to create a new database, just copy the existing one from Assets to data/data/my.package/databases/ and read from there.
The Android implementation of SQLite requires two conventions for the data base file. If you don't follow these conventions, Android's SQLite library won't read the data base correctly.
Every table must have an INTEGER PRIMARY KEY field named _id. (This may just be standard SQLite stuff.)
The data base must have a table named android_metadata. This table must have a TEXT column named locale and it should have one row with the locale name for the data. The value "en_US" works for me. Schema:
        CREATE TABLE android_metadata (locale TEXT)
Make sure that the data base in your assets conforms to these conventions.
The following site provides all your needs.Using your own SQLite database in Android applications

Example of how to implement ALTER TABLE [duplicate]

This question already has answers here:
adding a column to SQLite table in Android?
(3 answers)
Closed 8 years ago.
Ive asked this question several times and yet to get a COMPLETE answer... How to you implement the ALTER TABLE statement to add a column to a database. Can someone PLEASE give me an example?
Please read the SQLite ALTER TABLE reference, and this Android SQLite article:
database.execSQL("ALTER TABLE " + your_table_name + " ADD COLUMN " + new_col_name + " int");
ALTER TABLE db_name.mytable ADD COLUMN column_name VARCHAR(30)
That's for SQLite. Other databases may allow you to specify where the column gets put, but with SQLite it's appended to the end.
EDIT:I thought about this some more. In your question you asked for a complete answer. And someone identified that you asked essentially the same question just 5 hours before asking this one. Considering that none of the responses in that previous thread were what you were looking for (despite some of them offering complete SQL examples), it strikes me that a complete answer must include something more than the SQL and a few links to web tutorials.
In an effort to be thorough and complete, let me suggest that you consider the following books: Using SQLite (O'Reilly), and Learning Android (O'Reilly). In fact, the latter has a chapter (chapter 9) devoted to the Android database environment, meaning Android's implementation of SQLite.
People who have a lot of experience with databases, with programming, and with diverse operating systems often can get by with web manuals and a few tips on sites such as StackOverflow. But for the rest of us (myself included), when I really want to learn a topic that I consider important to me, I immerse myself in a couple of good books along the way.
I hope that you, or someone else who may be just getting started with such topics, find this advice helpful.
I've just encountered this and tried over and over and got the exception described here about column not exists, despite the alter table statement didn't throw any exception.
After two hours of trying, setting up a file backup storage, and whatever seemed viable here, I realized that I didn't include the new column in the "select query", but still tried to extract the data from the cursor, hence the column does not exist exception.

Categories

Resources