Permalink
Browse files

Merge pull request #42 from lfont/sqlite

Added basic SQLite support.
  • Loading branch information...
toptensoftware committed Jun 7, 2011
2 parents 2883330 + 82de0b8 commit a9b4161a2b626dd6199c13029d4b03ff911b4c3f
Showing with 17 additions and 0 deletions.
  1. +17 −0 PetaPoco/PetaPoco.cs
View
@@ -180,6 +180,7 @@ enum DBType
MySql,
PostgreSQL,
Oracle,
+ SQLite
}
DBType _dbType = DBType.SqlServer;
@@ -199,6 +200,7 @@ private void CommonConstruct()
else if (dbtype.StartsWith("SqlCe")) _dbType = DBType.SqlServerCE;
else if (dbtype.StartsWith("Npgsql")) _dbType = DBType.PostgreSQL;
else if (dbtype.StartsWith("Oracle")) _dbType = DBType.Oracle;
+ else if (dbtype.StartsWith("SQLite")) _dbType = DBType.SQLite;
if (_dbType == DBType.MySql && _connectionString != null && _connectionString.IndexOf("Allow User Variables=true") >= 0)
_paramPrefix = "?";
@@ -1243,6 +1245,21 @@ public object Insert(string tableName, string primaryKeyName, bool autoIncrement
}
OnExecutedCommand(cmd);
break;
+ case DBType.SQLite:
+ if (primaryKeyName != null)
+ {
+ cmd.CommandText += ";\nSELECT last_insert_rowid();";
+ DoPreExecute(cmd);
+ id = cmd.ExecuteScalar();
+ }
+ else
+ {
+ id = -1;
+ DoPreExecute(cmd);
+ cmd.ExecuteNonQuery();
+ }
+ OnExecutedCommand(cmd);
+ break;
default:
cmd.CommandText += ";\nSELECT @@IDENTITY AS NewID;";
DoPreExecute(cmd);

0 comments on commit a9b4161

Please sign in to comment.