dimanche 29 mars 2015

reteiving data from my database

i have a problem in retrieving data from my database . i use those scripts bellow to read the database and to select data from it





public ArrayList ReadFullTable (string tableName)
{
string query;
query = "SELECT * FROM " + tableName;
dbcmd = dbcon.CreateCommand ();
dbcmd.CommandText = query;
reader = dbcmd.ExecuteReader ();
ArrayList readArray = new ArrayList ();
while (reader.Read())
{
ArrayList lineArray = new ArrayList ();
for (int i = 0; i < reader.FieldCount; i++)
{
lineArray.Add (reader.GetValue (i));
} // This reads the entries in a row
readArray.Add (lineArray); // This makes an array of all the rows
}
return readArray; // return matches
}
public string QueryString(string tablename, string column, string col_name, string value)
{
string text = "Not Found";
string query;
query = "SELECT " + column + " FROM " + tablename + " WHERE " + col_name + "='" + value + "'";
dbcmd = dbcon.CreateCommand ();
dbcmd.CommandText = query;
reader = dbcmd.ExecuteReader ();

if(reader.Read())
text = reader.GetString(0);
else
Debug.Log("QueryString - nothing to read...");
reader.Close();
dbcon.Close();
return text;
}



and i have another script





private string firstName = "First Name";
private string lastName = "Last Name";
private string get = "GET";
private string find = "FIND";
private int DatabaseEntryStringWidth = 100;
private Vector2 scrollPosition ;
private ArrayList databaseData = new ArrayList ();

// This GUI provides us with a way to enter data into our database
// as well as a way to view it
void OnGUI ()
{
GUI.Box (new Rect (25, 25, Screen.width - 50, Screen.height - 50), "");
GUILayout.BeginArea (new Rect (50, 50, Screen.width - 100, Screen.height - 100));
// This first block allows us to enter new entries into our table
GUILayout.BeginHorizontal ();
firstName = GUILayout.TextField (firstName, GUILayout.Width (DatabaseEntryStringWidth));
lastName = GUILayout.TextField (lastName, GUILayout.Width (DatabaseEntryStringWidth));
get = GUILayout.TextField (get, GUILayout.Width (DatabaseEntryStringWidth));
find = GUILayout.TextField (find, GUILayout.Width (DatabaseEntryStringWidth));
GUILayout.EndHorizontal ();

if (GUILayout.Button ("Add to database"))
{
// Insert the data
InsertRow (firstName, lastName);
// And update the readout of the database
databaseData = ReadFullTable ();

}
// This second block gives us a button that will display/refresh the contents of our database
GUILayout.BeginHorizontal ();
if (GUILayout.Button ("Read Database"))
{
databaseData = ReadFullTable ();

}
if (GUILayout.Button ("Clear"))
{
databaseData.Clear ();
}
GUILayout.EndHorizontal ();

GUILayout.Label ("Database Contents");
scrollPosition = GUILayout.BeginScrollView (scrollPosition, GUILayout.Height (100));
foreach (ArrayList line in databaseData)
{
GUILayout.BeginHorizontal ();
foreach (object s in line)
{
GUILayout.Label (s.ToString (), GUILayout.Width (DatabaseEntryStringWidth));
}
GUILayout.EndHorizontal ();
}

GUILayout.EndScrollView ();
if (GUILayout.Button("search"))
{
get = GetDefinitation(find);
databaseData = ReadFullTable();
}
if (GUILayout.Button ("Delete All Data"))
{
DeleteTableContents ();
databaseData = ReadFullTable ();
}

GUILayout.EndArea ();
}

// Wrapper function for inserting our specific entries into our specific database and table for this file
private void InsertRow (string firstName, string lastName)
{
string[] values = new string[]{("'" + firstName + "'"), ("'" + lastName + "'")};
db.InsertInto (TableName, values);
}

// Wrapper function, so we only mess with our table.
private ArrayList ReadFullTable ()
{
return db.ReadFullTable(TableName);
}
public string GetDefinitation(string value)
{
return db.QueryString(TableName,"lastName","firstName", value);
}
// Another wrapper function...
private void DeleteTableContents ()
{
db.DeleteTableContents (TableName);
}
}



all the button works fine but the problem is in the button called 'search' when i click on it i have an error "SqliteSyntaxException: out of memory" i can't find where the problem is ?!! can anyone help me please ?! thank you


Aucun commentaire:

Enregistrer un commentaire