peterhuene / sqlite-net-wp8

A C++/CX wrapper for SQLite functions that sqlite-net depends on. Can be used as an alternative to csharp-sqlite on Windows Phone 8. This library is released under the MIT license.
MIT License
74 stars 65 forks source link

[sqlite3_bind_parameter_index] method always return 0 #3

Closed ghost closed 11 years ago

ghost commented 11 years ago

using this project on windows phone 8, with native SQLite 3.7.15.1 , sqlite3_bind_parameter_index always return 0. Any help, thank!

peterhuene commented 11 years ago

Hi dingoxiong,

Thanks for reporting this. Do you have an example piece of code that demonstrates the problem?

ghost commented 11 years ago

1). Add a new method in SQLiteConnection: public SQLiteCommand CreateCommand(string cmdText, Dictionary <string,string> paras){ if (!_open){ throw SQLiteException.New(SQLite3.Result.Error, "Cannot create commands from unopened database"); } else{ var cmd = NewCommand(); cmd.CommandText = cmdText; foreach (var o in paras){ cmd.Bind(o.Key, o.Value); //Binding Key and Value here! } return cmd; } }

2). Add a new method in SQLiteConnection: public int Execute(string query, Dictionary <string, string> paras){ var cmd = CreateCommand(query, paras); if (TimeExecution){ if (_sw == null){ _sw = new System.Diagnostics.Stopwatch(); } _sw.Reset(); _sw.Start(); } var r = cmd.ExecuteNonQuery(); if (TimeExecution) { _sw.Stop(); _elapsedMilliseconds += _sw.ElapsedMilliseconds; Debug.WriteLine(string.Format("Finished in {0} ms ({1:0.0} s total)", _sw.ElapsedMilliseconds, _elapsedMilliseconds / 1000.0)); } return r; }

3). then call this like: string sqltext = "select count(*) from sometable where name = :name and state=:state"; Dictionary<string, string> paras = new Dictionary <string, string> (); paras.Add("name","bear"); paras.Add("state", "1"); ...... connection.Execute(sqltext, paras);

then: SQLiteCommand.BindALL(Sqlite3Statement stmt) in this method, b.Index = SQLite3.BindParameterIndex(stmt, b.Name); this line always return 0;

peterhuene commented 11 years ago

In your code above, what is stmt when you call SQLite3.BindParameterIndex? I don't see it declared.