| View previous topic :: View next topic |
| Author |
Message |
tedius

Joined: Fri Apr 08, 2005 4:20 pm Posts: 83 Location: Cambridge, England
|
Posted: Mon Nov 28, 2005 2:11 pm Post subject: [Solved] Mono and Sqlite |
|
|
I'm having some problems with a database application I'm writing in C# on mono. To be more precise it is the SqliteParameter object that is causing me hassle.
This is a snippet of my code;
| Code: | public static class Connection
{
private static SqliteConnection mConn = null;
public static bool Connect(string filename)
{
if (mConn != null)
mConn.Close();
string connString = "version=3,URI=file:" + filename;
mConn = new SqliteConnection(connString);
return true;
}
public static void Create()
{
string sql = @"CREATE TABLE _table
(param TEXT NOT NULL,
value TEXT NOT NULL);
SqliteCommand cmd = new SqliteCommand(sql, mConn);
// insert the default values
Insert("version", mdVersion);
Insert("ready", true);
}
private static void Insert(string var, object val)
{
string sql = "INSERT INTO _table VALUES (@Param, @Val)";
SqliteCommand cmd = null;
SqliteParameter param = null;
try
{
mConn.Open();
cmd = new SqliteCommand(sql, mConn);
param = new SqliteParameter();
param.ParameterName = "@Param";
param.Value = var;
cmd.Parameters.Add(param);
param = new SqliteParameter();
param.ParameterName = "@Val";
param.Value = val.ToString();
cmd.Parameters.Add(param);
cmd.ExecuteNonQuery();
}
finally
{
if (cmd != null)
cmd.Dispose();
mConn.Close();
}
}
}
|
Can any one see what I'm doing wrong with this. When I run it I get the following error;
| Code: | Unhandled Exception: System.ApplicationException: unrecognized token: "@"
in <0x00186> Mono.Data.SqliteClient.SqliteCommand:Prepare ()
in <0x00085> Mono.Data.SqliteClient.SqliteCommand:ExecuteReader (CommandBehavior behavior, Boolean want_results, System.Int32 rows_affected)
in <0x00023> Mono.Data.SqliteClient.SqliteCommand:ExecuteNonQuery ()
in <0x001a9> PiggyBank.Database.Connection:Insert (System.String var, System.Object val)
in <0x00040> PiggyBank.Database.Connection:Create ()
in <0x00033> MainClass:Main (System.String[] args) |
Some one please help, as I'm pulling out my heir
[edit] ups I mean hair [/edit]
Last edited by tedius on Tue Nov 29, 2005 10:39 am; edited 2 times in total |
|
| Back to top |
|
 |
M-Saunders Moderator

Joined: Mon Apr 11, 2005 1:14 pm Posts: 2881
|
Posted: Mon Nov 28, 2005 2:23 pm Post subject: Re: Mono and Sqlite |
|
|
| tedius wrote: | Some one please help, as I'm pulling out my heir  |
Hey, just because it won't run, doesn't mean you need to cut people out of your will.
(Sorry. Had to do it.)
M  |
|
| Back to top |
|
 |
tommieb
Joined: Sat Oct 22, 2005 2:08 pm Posts: 6
|
Posted: Mon Nov 28, 2005 3:12 pm Post subject: RE: Re: Mono and Sqlite |
|
|
Hmmm....have you tried taking out the @ from the param.ParameterName = "@Param"; line??
HTH,
Tom. |
|
| Back to top |
|
 |
tommieb
Joined: Sat Oct 22, 2005 2:08 pm Posts: 6
|
Posted: Mon Nov 28, 2005 3:16 pm Post subject: RE: Re: Mono and Sqlite |
|
|
| Oh yeah, I'd also guess you'd have to declare the parameters in the line that contains the SQL....INSERT INTO _table VALUES (@Param, @Val), from my mssql exp, the db manager would need to know what are the parameter typings for each of them...perhaps something like this - DECLARE @Param Text, DECLARE @Val Text prior to the INSERT sql? |
|
| Back to top |
|
 |
tedius

Joined: Fri Apr 08, 2005 4:20 pm Posts: 83 Location: Cambridge, England
|
Posted: Mon Nov 28, 2005 3:42 pm Post subject: |
|
|
| From what I have understand from the Mono and .NET documentation then the parameter substitution is happening before the sql is passed to Sqlite. As for the other suggestion, I tried that and it had no effect. |
|
| Back to top |
|
 |
tedius

Joined: Fri Apr 08, 2005 4:20 pm Posts: 83 Location: Cambridge, England
|
Posted: Tue Nov 29, 2005 10:38 am Post subject: [Solved] Mono and Sqlite |
|
|
I have found out what the problem is.
I'm using sqlite3 and for this they have changed the @ for :. So once I had replaced all my @ signs with : signs it worked fine. |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|