Science topic

SQL Programming - Science topic

Explore the latest questions and answers in SQL Programming, and find SQL Programming experts.
Questions related to SQL Programming
  • asked a question related to SQL Programming
Question
5 answers
Orchid related data in SQLite DB format attached in Asset folder with Android Application and application work only upto Android 8 (API level 26) but the inbuilt Database is not visible in Android 9 (API level 28) . What's the reason behind this?
Application built in Eclipse Juno Framework
Relevant answer
Answer
Below code is used for calling/attaching that DB file (saved in asset folder) with application
public class DataBaseHandler extends SQLiteOpenHelper {
public static String DB_PATH;
public static String DB_NAME = "orchidpedia.db";
public SQLiteDatabase database;
public final Context context;
public SQLiteDatabase getDb() {
return database;
}
public DataBaseHandler(Context context, String databaseName) {
super(context, databaseName, null, 1);
this.context = context;
String packageName = context.getPackageName();
DB_PATH = String.format("/data/data/nrco.orchidopedia/databases/", packageName);
DB_NAME = databaseName;
openDataBase();
}
public void createDataBase() {
boolean dbExist = checkDataBase();
if (!dbExist) {
this.getReadableDatabase();
try {
copyDataBase();
} catch (IOException e) {
Log.e(this.getClass().toString(), "Copying error");
throw new Error("Error copying database!");
}
} else {
Log.i(this.getClass().toString(), "Database already exists");
}
}
private boolean checkDataBase() {
SQLiteDatabase checkDb = null;
try {
String path = DB_PATH + DB_NAME;
checkDb = SQLiteDatabase.openDatabase(path, null,
SQLiteDatabase.OPEN_READONLY);
} catch (SQLException e) {
Log.e(this.getClass().toString(), "Error while checking db");
}
if (checkDb != null) {
checkDb.close();
}
return checkDb != null;
}
private void copyDataBase() throws IOException {
assets
InputStream externalDbStream = context.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream localDbStream = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = externalDbStream.read(buffer)) > 0) {
localDbStream.write(buffer, 0, bytesRead);
}
localDbStream.close();
externalDbStream.close();
}
public SQLiteDatabase openDataBase() throws SQLException {
String path = DB_PATH + DB_NAME;
if (database == null) {
createDataBase();
database = SQLiteDatabase.openDatabase(path, null,
SQLiteDatabase.OPEN_READWRITE);
}
return database;
}
@Override
public synchronized void close() {
if (database != null) {
database.close();
}
super.close();
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
  • asked a question related to SQL Programming
Question
3 answers
I'm trying to delete a table and create them again in PostgreSQL, but, in more than 24 hours, the command DROP TABLE or TRUNCATE don't finished.
This table have a lot of tuples (millions), but, this command don't have to be fast?
What can I do to delete this table completely?
Relevant answer
What was the update?
  • asked a question related to SQL Programming
Question
5 answers
I have a column number 1,2,3,4,.............................................600. I am using here
SELECT 1,2,3,4,5 FROM tbl;
here i get only the column no with data consisting of 1, 2, 3, 4,5 ....
My question is how I get from 1 to 16.
After i need the data from 18 to 59
and continue
i want to group...
please tell me what syntax will i use?
Relevant answer
Answer
Hi Hirak!
You can try this:
SELECT *
FROM table
WHERE (ID BETWEEN '1' AND '16')
OR (ID BETWEEN '18' AND '59')
OR (ID BETWEEN '100' AND '110')
;
  • asked a question related to SQL Programming
Question
12 answers
I need to retrieve fields from a relational database that has more than twenty tables. I am having difficulty in extracting required 63 fields from the database. Someone advice please.
Relevant answer
Answer
Hi Ken,
We can best help if you'll output the DDL schema (script it) and define the query requirements needed. There's much to consider, especially if the database isn't normalized or lacks data-integrity.
Les
  • asked a question related to SQL Programming
Question
5 answers
I use the following query for retrieving data from SQLite database in android.But I do'nt know how to retrieve data randomly?
Cursor c=db.query("questiondata",null,null,null,null,null,null);
  • asked a question related to SQL Programming
Question
5 answers
I'm try to create and application with CodeIngiter, I use a MySQL DB for it, but I need have access to others Databases make it with SQL Server, recompile information from them and integrate to my MySQL DB on my application.
Relevant answer
Answer
Have you tried anything in particular?
For starters you are going to have to use the SQL server driver, and install it if you don't have it yet. More info on this StackOverflow question(see bellow).
After that you are going to have to switch between the two database drivers. You can find more info for that in the CI documentation(2nd link)
  • asked a question related to SQL Programming
Question
2 answers
I have set of multiple-choice questions that want to ask them from users for getting his/her performance in answering the questions.
Relevant answer
Answer
You may also want to look at OpenDataKit: https://opendatakit.org/.  It's a nice out-of-box solution for building forms, data collection and aggregation.
  • asked a question related to SQL Programming
Question
7 answers
I want to do research on the above mentioned topic. I need ur suggestions
  • asked a question related to SQL Programming
Question
11 answers
Inmon, Kimball, Hefesto or another? I'm currently building a data warehouse to pave the way for data mining, the goal of this work is to improve the process of decision-making in education policy. This requires knowing what the best architecture is.
Relevant answer
Its depend on what do you need, no matter what the architecture, its go back to the purpose to build datawarehouse where we need to deliver database environment which can create best sql performance when access data from datawarehouse
you can create star schema or snowflake, top down or bottom up, its depend on how best performance your sql to access datawarehouse rather than from oltp.
  • asked a question related to SQL Programming
Question
9 answers
I want to find a special string in a given set of strings. For example I have an address, street A 59 (or just A 59, street has not been entered in the database), in contrast, there exists a park with the name of A or other places. I want to search the keyword A and find all the streets with the name A, not other places, e.g. park. and there are thousands of rows in the database.
I use this command for my situation: UPDATE my-column SET my-column = 2
WHERE my-column LIKE '%A%'
But I don't know how to search for string A plus a number in front of it (I mean search A 12, A 13,... simultaneously (A+Number). Could you please help me?
Thank you so much in advance.
Relevant answer
Answer
You have several options in SQL Server: either you use PATINDEX or RegexGroup.
Using PATINDEX Function: this function will return the index of the starting position of first occurrence the pattern provided or 0 if no pattern matched.
e.g.
select dictinct substring([Address], NULLIF(PATINDEX('%[a-z][A-Z] \d+%', [Address]),0),4) from [AddressTable]
Be aware that you do not get the end position and this will only work nicely if you know how long your matching string will be. In this case I took a length of 4 a 'A 59' is 4 characters long.
And this is how it works for the second:
use regular expression (regex) pattern matching.
e.g.
select distinct dbo.RegexGroup( [Address], N'.*?(?<housenumber>[a-z][A-Z] \d+).*', N'housenumber' ) from [AddressTable]
Both queries would only return the 'A 59' part from the string 'Big Street A 59, West Side' in the column Address. Be aware that both queries will have a row with NULL if there is at least one column that doesn't match!
You can read more on regex pattern matching here:
More on PATINDEX and various other methods of getting only the matching string back here:
(I haven't tested any of these solutions as I do not have access to a SQL Server atm)
  • asked a question related to SQL Programming
Question
4 answers
I want to read all transactions such as insert, update, delete for a specific table and database in SQL Server 2005 or SQL Server 2008
Relevant answer
Answer
For specific table you can use triggers.
  • asked a question related to SQL Programming
Question
6 answers
DECLARE @RowCount INT
SET @RowCount = (SELECT COUNT(ID) FROM Table1)
DECLARE @I INT
SET @I = 1
WHILE (@I <= @RowCount)
BEGIN
DECLARE @word VARCHAR(50), @len int
SELECT @word = word, @len = LEN(@word) FROM Table1 WHERE ID = @I
WHILE @len>0
BEGIN
INSERT INTO Table2 (base, part) VALUES (@word, SUBSTRING(@word,1,@len))
SET @len=@len-1
END
SET @I = @I + 1
END
Relevant answer
Answer
Try to save data and log files in different disks and rebuild index ,update statistics
  • asked a question related to SQL Programming
Question
6 answers
Transactions control the queries that perform complete or rollback.
Relevant answer
Answer
The exact syntax depends on your DBMS.
Start a transaction with "begin transaction",
then do some data manipulation (inserts, updates,
deletes), then do "commit transaction" if no
error occurred, or do a "rollback transaction"
in case of an error.
Some DBMS allow nested transactions. Most DBMS
allow different isolation levels: "set transaction isolation
level <no>", where <no> is a number. The transaction
isolation levels are standardized and define how
much data one transaction is allowed to see from
other ones.
In some cases a transaction must wait for the completion
of another one. I strongly recommend to make experiments
with isolation levels. Open two shells (like ISQL, SQLPLUS,
could be on the same machine) and set up two transactions.
Observe what happens when a command halts because
of the isolation level, and how it continues after the
causing other transation ends.
Regards,
Joachim
  • asked a question related to SQL Programming
Question
1 answer
I need a function that doesn't have limitation of 32 kb buffer size like "encode to base64"
an example in attachment.