E
E
Evgeny Vasilenko2016-05-05 20:52:57
Android
Evgeny Vasilenko, 2016-05-05 20:52:57

What is the best way to store SQL queries?

Good afternoon. Please share your experience where you store sql queries. I used to create interfaces or abstract classes in which I created String constants of the form

CREATE TABLE IF NOT EXISTS "post" 
("_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
 "link" TEXT NOT NULL UNIQUE , 
"read" BOOL NOT NULL )

And then in the derived class SQLiteOpenHelper did the following
@Override
public void onCreate(SQLiteDatabase db) {
       db.execSQL(SomeClass.SQL_CREATE_TABLE);
}

Perhaps there are some better ways to store the requests themselves? Perhaps in a separate sql file or in resources? Perhaps even as a string-array in resources, if you want to create several tables in turn?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2016-05-06
@tsklab

I store it as a sql script, along with the source files of the program, under the CVS version control system.

S
Sergey Bondarenko, 2016-05-06
@sergyb

Always store queries in the form of stored procedures (Stored Procedure) in the used DBMS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question