I am developing a Ruby on Rails application, and I am constructed complicated queries.
Is there a way to test if the results that I have is correct?
Unit tests provide testing for each model, but how I can test if my results are correct?
I am developing a Ruby on Rails application, and I am constructed complicated queries.
Is there a way to test if the results that I have is correct?
Unit tests provide testing for each model, but how I can test if my results are correct?
I hope to get a address list and corresponding Thread_id list, so I write the function GetListPhoneNumberForConversation and GetListThread_idForConversation.
You know sometimes the address will retun null in draft sms. Please view the document getting "null" as an address for a draft sms
So, I use max(address) as order by parameter, I hope that it can exclude null address record.
It can do return not null address, but I don't know if my code is correct and the address list and the Thread_id list are matched.
private static List<String> GetListPhoneNumberForConversation(Context myContext){
return GetListByField(myContext,"address");
}
public static List<String> GetListThread_idForConversation(Context myContext){
return GetListByField(myContext,"thread_id");
}
private static List<String> GetListByField(Context myContext,String field){
List<String> listbyField=new ArrayList<String>();
Uri uri=PublicParFun.GetUriBySMSRange(SMSRange.All);
String[] projection = new String[] {field};
Cursor cur = myContext.getContentResolver().query(uri,
projection,
"1=1 ) group by ( thread_id", null, "max(address)");
listbyField=FillListField(cur,field);
cur.close();
return listbyField;
}
private static List<String> FillListField(Cursor cur,String field){
List<String> mListField=new ArrayList<String>();
while(cur.moveToNext()){
String s=cur.getString(cur.getColumnIndex(field));
if (s!=null) {
mListField.add(s);
}
}
return mListField;
}
public static Uri GetUriBySMSRange(SMSRange mSMSRange){
Uri uri=null;
final String SMS_URI_ALL = "content://sms/";
final String SMS_URI_INBOX = "content://sms/inbox";
final String SMS_URI_SEND = "content://sms/sent";
final String SMS_URI_OUTBOX = "content://sms/outbox";
final String SMS_URI_DRAFT = "content://sms/draft";
switch (mSMSRange){
case All:
uri = Uri.parse(SMS_URI_ALL);
break;
case Inbox:
uri = Uri.parse(SMS_URI_INBOX);
break;
case Sentbox:
uri = Uri.parse(SMS_URI_SEND);
break;
case Outbox:
uri = Uri.parse(SMS_URI_OUTBOX);
break;
case Draft:
uri = Uri.parse(SMS_URI_DRAFT);
break;
}
return uri;
}
I did an android application, its about the pharmacy on duty. I want to change it in every month but when I download it my device from google store, it shows the old month information. So what can I do for delete old month information and show new month information? Here is my code for this app.
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.TextView;
import static com.ahmety.eczanezonguldak.Sbtalapli.*;
public class Alapli extends Activity {
private Vtalapli data;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alapli);
data = new Vtalapli(this);
try{addData("","","","");
addData("17.06.2015","Pharmacy Name ","pharmacy addres","pharmacy tel no");
Cursor cursor = getData();
showData(cursor);
}
finally{
data.close();
}
}
private void addData(String date, String pharmacy, String address, String tel){
SQLiteDatabase db = data.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(DATE, date);
values.put(PH,pharmacy);
values.put(ADDRESS,address);
values.put(TEL,tel);
db.insertOrThrow(TABLE_ALAPLI, null, values);
}
private static String[] SELECT = {DATE, PH, ADDRESS,TEL};
private Cursor getData(){
SQLiteDatabase db = data.getReadableDatabase();
Cursor cursor = db.query(TABLE_ALAPLI, SELECT, null, null, null, null, null);
startManagingCursor(cursor);
return cursor;
}
private void showData(Cursor cursor){
StringBuilder builder = new StringBuilder(" Nöbetçi Eczane/Alapli\n\n\n "
+ " Tarih Eczane Addres Tel\n");
while(cursor.moveToNext()){
String date = cursor.getString((cursor.getColumnIndex(DATE)));
String ph = cursor.getString((cursor.getColumnIndex(PH)));
String address = cursor.getString((cursor.getColumnIndex(ADDRESS)));
String tel = cursor.getString((cursor.getColumnIndex(TEL)));
builder.append(date).append(" ");
builder.append(ph).append(" ");
builder.append(address).append(" ");
builder.append(tel).append("\n");
}
TextView text = (TextView)findViewById(R.id.textalapli);
text.setText(builder);
}
}
I realize that handcrafting SQL statements is evil. I also realize that the spontaneous answer of everyone seeing this post will be "Use parameters". I have found several occurences of similar questions around here, but I can't find out how they apply to my specific problem.
I use System.Data.SQLite with C#. I want to dynamically create a VIEW, say listview_asdf which I then can access inside a library with simple SELECT * FROM listview_asdf statements. That library uses loads of automatically generated statements for accessing my view.
Problem is, at one point I need to create a view like this:
CREATE VIEW listview_asdf AS SELECT * FROM tbl_asdf WHERE id IN (1,2,3)
not knowing how many and which parameters I have in the IN() list. Actually, the list will be different each time I use it (I delete the views in their Dispose() methods). Creating the view does - as far as I understand the relevant google result - not allow to use parameters.
So, I need to take an arbitrary-length array of parameters (easy) and write the CREATE VIEW statement with an IN (...) clause. Here, I need to insert the parameter values. This is no problem in case of integers, as shown above, but for strings or other types (System.DateTime comes to mind) I need some kind of escaping.
Else, I need some way of getting around the necessity of escaping. I don't know of any solution to either except the ominous
sql = sql.Replace("'","''");
which, as User Aur Saraf points out here, is a sure way of losing my job (which I do like).
Any ideas for a way out?
I use this code to search for Column A. What modification should I make if I want to search Column A and Column B simultaneously?
String sql = "SELECT * FROM " + TABLE_NAME +
" WHERE " + ColumnA + " LIKE ? ORDER BY " + ColumnA + " LIMIT 100";
I've tried this but it's not work:
String sql = "SELECT * FROM " + TABLE_NAME +
" WHERE " + ColumnA + " LIKE ? ORDER BY " + ColumnA + " LIMIT 100 OR SELECT * FROM " + TABLE_NAME +
" WHERE " + ColumnB + " LIKE ? ORDER BY " + ColumnB + " LIMIT 100";
Any mistake I made?
Im making a login and register system and if need to check if the user already exits so I wrote this function in my database handler to check it.
public boolean checkIfUserExits(String username){
SQLiteDatabase db = this.getWritableDatabase();
String query = "SELECT * FROM " + TABLE_NAME + " WHERE username=" + "\"" + username + "\"";
Cursor cursor = db.rawQuery(query, null);
if(cursor.getCount() <= 0){
cursor.close();
return false;
}
cursor.close();
return true;
}
But the problem if that i always getting a true. Thanks for help.
I am creating an app to store some data in database which will be added or updated from app itself. The data which i will enter is gonna be in english and arabic language. I want an edittext to ask for english name and another edittext to ask for arabic name of a product in a form.
Can u please help me with it?
While searching I found an open source arabic keyboard
If you can tell me how can i use it to implement on an edittext in my app for arabic input then that would also work. Thanx in advance.