ことの始まりは、つい先日 SourceForge.net の RSS から ADO.NET 2.0 Provider for SQLite が 1.0.42.0 から 1.0.43.0 にバージョンアップしたのを知ったので、早速バージョンアップしてみました。

インストールも特に問題なく完了。SQLite3.4かぁ。ふーん。

でもって、開発中のアプリのコーディングを再開してしばらくすると、不可解なエラーが。

色々調べてみると、SQLのMAX関数やCOUNT関数で件数とかをチェックしているロジックが機能しない。intで返ってくるはずのところがstringになっていたり。それで変換できないエラーとか起こっている。なんじゃこれ!
ウーン、特に手を入れてないのにな…、と、ふと DataSet.Designer.cs を直接除いてみると、なんかおかしい。ん?

なんで COUNT で件数返すだけなのに return が string なんだ??

とりあえず、ADO.NET 2.0 Provider for SQLiteのバージョンを1.0.42.0に戻してみると、ソースも元に戻る。ウーン、バグなんだろうか?それともこういう仕様なんだろうか?

とりあえず、時間も無いので、1.0.42.0で開発続行しました。

SQLite-1.0.42.0-binary.exe

C#:
  1. // MAX() にて最大値を求めているクエリー
  2. [System.Diagnostics.DebuggerNonUserCodeAttribute()]
  3. [System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  4. public virtual System.Nullable ScalarQueryTest1(long xxx_id) {
  5. System.Data.SQLite.SQLiteCommand command = this.CommandCollection[6];
  6. command.Parameters[0].Value = ((long)(xxx_id));
  7. System.Data.ConnectionState previousConnectionState = command.Connection.State;
  8. if (((command.Connection.State & System.Data.ConnectionState.Open)
  9. != System.Data.ConnectionState.Open)) {
  10. command.Connection.Open();
  11. }
  12. object returnValue;
  13. try {
  14. returnValue = command.ExecuteScalar();
  15. }
  16. finally {
  17. if ((previousConnectionState == System.Data.ConnectionState.Closed)) {
  18. command.Connection.Close();
  19. }
  20. }
  21. if (((returnValue == null)
  22. || (returnValue.GetType() == typeof(System.DBNull)))) {
  23. return new System.Nullable();
  24. }
  25. else {
  26. return new System.Nullable(((long)(returnValue)));
  27. }
  28. }

C#:
  1. // COUNT() にて最大値を求めているクエリー
  2. [System.Diagnostics.DebuggerNonUserCodeAttribute()]
  3. [System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  4. public virtual System.Nullable ScalarQueryTest2(long xxx_id) {
  5. System.Data.SQLite.SQLiteCommand command = this.CommandCollection[7];
  6. command.Parameters[0].Value = ((long)(xxx_id));
  7. System.Data.ConnectionState previousConnectionState = command.Connection.State;
  8. if (((command.Connection.State & System.Data.ConnectionState.Open)
  9. != System.Data.ConnectionState.Open)) {
  10. command.Connection.Open();
  11. }
  12. object returnValue;
  13. try {
  14. returnValue = command.ExecuteScalar();
  15. }
  16. finally {
  17. if ((previousConnectionState == System.Data.ConnectionState.Closed)) {
  18. command.Connection.Close();
  19. }
  20. }
  21. if (((returnValue == null)
  22. || (returnValue.GetType() == typeof(System.DBNull)))) {
  23. return new System.Nullable();
  24. }
  25. else {
  26. return new System.Nullable(((long)(returnValue)));
  27. }
  28. }

SQLite-1.0.43.0-binary.exe

C#:
  1. // MAX() にて最大値を求めているクエリー
  2. [System.Diagnostics.DebuggerNonUserCodeAttribute()]
  3. [System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  4. public virtual object ScalarQueryTest1(long xxx_id) {
  5. System.Data.SQLite.SQLiteCommand command = this.CommandCollection[6];
  6. command.Parameters[0].Value = ((long)(xxx_id));
  7. System.Data.ConnectionState previousConnectionState = command.Connection.State;
  8. if (((command.Connection.State & System.Data.ConnectionState.Open)
  9. != System.Data.ConnectionState.Open)) {
  10. command.Connection.Open();
  11. }
  12. object returnValue;
  13. try {
  14. returnValue = command.ExecuteScalar();
  15. }
  16. finally {
  17. if ((previousConnectionState == System.Data.ConnectionState.Closed)) {
  18. command.Connection.Close();
  19. }
  20. }
  21. if (((returnValue == null)
  22. || (returnValue.GetType() == typeof(System.DBNull)))) {
  23. return null;
  24. }
  25. else {
  26. return ((object)(returnValue));
  27. }
  28. }

C#:
  1. // COUNT() にて最大値を求めているクエリー
  2. [System.Diagnostics.DebuggerNonUserCodeAttribute()]
  3. [System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  4. public virtual string ScalarQueryTest2(long xxx_id) {
  5. System.Data.SQLite.SQLiteCommand command = this.CommandCollection[7];
  6. command.Parameters[0].Value = ((long)(xxx_id));
  7. System.Data.ConnectionState previousConnectionState = command.Connection.State;
  8. if (((command.Connection.State & System.Data.ConnectionState.Open)
  9. != System.Data.ConnectionState.Open)) {
  10. command.Connection.Open();
  11. }
  12. object returnValue;
  13. try {
  14. returnValue = command.ExecuteScalar();
  15. }
  16. ブックマークに追加する