vendredi 27 février 2015

Need Help for SQLite Database where clause query

Hii I am trying to get a value from listview from one activity and pass that value into where clause in sqlite query in another activity. But when I query gets executed it gives Unfortunately app has stopped working error. Code is as follows:



import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class newclass extends Activity {
private static final Context Context = null;
SQLiteDatabase db1=null;
private static String DBNAME ="PERSONS.db";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newacti);
TextView Textv = (TextView)findViewById(R.id.tv1);
Intent iin= getIntent();
Bundle b = iin.getExtras();
db1 = openOrCreateDatabase(DBNAME,Context.MODE_PRIVATE,null);
if(b!=null)
{
String j =(String) b.get("name");
Textv.setText(j);
//Below 2 lines gives an error "Unfortunately app has stopped working error"
String sqlQuery = "select * from TBUSER where ID='"+ j+"'";
Toast.makeText(Context, sqlQuery, Toast.LENGTH_LONG).show();
/*db1 = openOrCreateDatabase(DBNAME,Context.MODE_PRIVATE,null);
Cursor c= db1.rawQuery(sqlQuery, null);
if (c != null && c.moveToFirst()) {
do {
//do something
} while (c.moveToNext());
}*/

}
}

}


Can anybody say me whats an error. Thank You in Advance.


Error when trying to compile using sqlite3_open in Visual Studio 2013

I'm working in a Cocos2dx (c++) win 32 project and trying to use sqlite to save the game data. My knowledge of c++ / Visual Studio is very limited right now.


This is part of the code that I'm trying to compile.



#include <sqlite3\include\sqlite3.h>
...
void HelloWorld::SaveAndLoadTest()
{
sqlite3 *pdb = NULL;
sqlite3_open("writablePath", &pdb);
...
}


But when I try to compile the line with the sqlite3_open command I get the following error:


Error 7 error LNK2019: unresolved external symbol _sqlite3_open referenced in function...


I've been trying to find an answer for this many hours. The most similar question I found was this one but I don't understand the answer. Error: undefined reference to `sqlite3_open'



You need to link the sqlite3 library along with your program:



g++ main.cpp -lsqlite3


I'm new to Visual Studio and I don't understand how to solve this, anyone?


Android SQLite tables realationship questions

Okay I am no good with databases. I have one table that consist of user details which is unique id, username, password and his name. Once the user logs in, how do I relate the user's data back to him so that all data associated to his ID returns when he request it?


Example user wants to add ToDo task on the database, and return ToDo's through listView. Do I create new table that contains something like this when FOREIGN KEY (userId) REFERENCES members(_id) and can I create multiple tables to reference to my members table?


Sorry for the basic questions I have just recently started developing in Android and using SQL


How to use SQLite3 library in MSVC project?

I want to build a native C++ application using sqlite3.dll. I tried to build it from SQLite amalgamation source. It creates the dll and the lib file (is the lib the dll's import library?) but when I use it in my project, I get errors like



error LNK2019: unresolved external symbol _sqlite3_open referenced in function...


I tried to prefix underscore in the def file (I set the Module Definition File in the Linker Input options), but tough luck.


What am I doing wrong? It looks like the reference is missing: I added SQLite.lib (the lib file I created) in the Additional Dependencies in the Project where I want to use it. I added its directory to Library Directories.


I use MSVC 2010 Express and I am just about to curse it.


Python error: EOL while scanning string literal

Some background information


I am using SQLite to access a database and retrieve the desired information. I'm using ElementTree in Python version 2.6 to create an XML file with that information.


Code


Here is the code I'm using to create an XML file from the database schema. I've denoted the location the error occurs with a comment.



import sqlite3
import xml.etree.ElementTree as ET

db = sqlite3.connect("dataload.db")
root = ET.Element("databaseConfiguration")


software_attributes = ["id", "functionalDesignationHardware", "hwfin", "identname", "partnumber",
"repfin", "targetHardwareID"]

software = db.cursor().execute("SELECT %s from SOFTWARE_" % ", ".join([i + "_" for i in software_attributes]))
software_Data = software.fetchall()
for sw in software_Data:
sw_node = ET.SubElement(root, "Software")
for i in range(1, len(software_attributes)):
sw_node.set(software_attributes[i], str(sw[i]))


target_attributes = ["id", "functionalDesignationSoftware", "installscriptpathname", "ata", "status",
"swfin", "targetOSFC", "timestamp"]


tree = ET.ElementTree(root)

from xml.dom import minidom
print minidom.parseString(ET.tostring(root)).toprettyxml(indent = " ")

## The error pops up at this line (when trying to generate the XML) ##
tree.write("New_Database.xml)


Question


How do I fix this error? I've seen some other questions where quotes had to be added or edited - do I need to do something similar, and how?


~


Notes


Everything but the tree.write("New_Database.xml") line works as expected for my purposes (so far).


Please let me know if you wish for me to provide any more information.


~


Thanks in advance!


sqlite3 shortens float value

I do a simple:


latitude:String = String.fromCString(UnsafePointer(sqlite3_column_text(statement, 11)))!


The value in the Database is "real". In the database I have 51.234183426424316 (verified using Firefox'SQLite Manager)


With the above I get in my String only: 51.2341834264243 (the last two digits are missing with is not acceptable working with coordinates)


Any explanations? Solutions?


MvvmCross SQLite composite key

I am trying to learn how to support composite primary keys in MvvmCross using the MvvmCross Community SQLite Plugin. According to this answer it has been supported since at least Oct 2014. Does anyone know how to do this?


If I implement a model class with two [PrimaryKey] attributes then the call to CreateTable will throw a SQLite exception.


There doesn't appear to be a CompositeKey attribute.



  • My Core PCL project references Cirrious.MvvmCross.Community.Plugins.Sqlite via NuGet.

  • My Droid project references Cirrious.MvvmCross.Community.Plugins.Sqlite & Cirrious.MvvmCross.Community.Plugins.Sqlite.Droid.