Skip to content

Commit

Permalink
Merge pull request #42 from lfont/sqlite
Browse files Browse the repository at this point in the history
Added basic SQLite support.
  • Loading branch information
toptensoftware committed Jun 7, 2011
2 parents 2883330 + 82de0b8 commit a9b4161
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions PetaPoco/PetaPoco.cs
Expand Up @@ -180,6 +180,7 @@ enum DBType
MySql, MySql,
PostgreSQL, PostgreSQL,
Oracle, Oracle,
SQLite
} }
DBType _dbType = DBType.SqlServer; DBType _dbType = DBType.SqlServer;


Expand All @@ -199,6 +200,7 @@ private void CommonConstruct()
else if (dbtype.StartsWith("SqlCe")) _dbType = DBType.SqlServerCE; else if (dbtype.StartsWith("SqlCe")) _dbType = DBType.SqlServerCE;
else if (dbtype.StartsWith("Npgsql")) _dbType = DBType.PostgreSQL; else if (dbtype.StartsWith("Npgsql")) _dbType = DBType.PostgreSQL;
else if (dbtype.StartsWith("Oracle")) _dbType = DBType.Oracle; 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) if (_dbType == DBType.MySql && _connectionString != null && _connectionString.IndexOf("Allow User Variables=true") >= 0)
_paramPrefix = "?"; _paramPrefix = "?";
Expand Down Expand Up @@ -1243,6 +1245,21 @@ public object Insert(string tableName, string primaryKeyName, bool autoIncrement
} }
OnExecutedCommand(cmd); OnExecutedCommand(cmd);
break; 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: default:
cmd.CommandText += ";\nSELECT @@IDENTITY AS NewID;"; cmd.CommandText += ";\nSELECT @@IDENTITY AS NewID;";
DoPreExecute(cmd); DoPreExecute(cmd);
Expand Down

0 comments on commit a9b4161

Please sign in to comment.