Permalink
Browse files

Added hstore support

  • Loading branch information...
1 parent 865d779 commit 22e4fdb3a3dd171a2ed71ca087fd16f48dd560a7 @roji roji committed Jun 20, 2014
Showing with 29 additions and 6 deletions.
  1. +2 −1 Npgsql/NpgsqlTypes/NpgsqlDbType.cs
  2. +8 −0 Npgsql/NpgsqlTypes/NpgsqlTypesHelper.cs
  3. +13 −4 tests/CommandTests.cs
  4. +6 −1 tests/TestBase.cs
@@ -73,7 +73,8 @@ public enum NpgsqlDbType
Name,
Abstime,
MacAddr,
- Json
+ Json,
+ Hstore
}
}
@@ -453,6 +453,10 @@ private static NpgsqlNativeTypeMapping PrepareDefaultTypesMap()
BasicNativeToBackendTypeConverter.StringToTextText,
BasicNativeToBackendTypeConverter.StringToTextBinary);
+ nativeTypeMapping.AddType("hstore", NpgsqlDbType.Hstore, DbType.Object, false,
+ BasicNativeToBackendTypeConverter.StringToTextText,
+ BasicNativeToBackendTypeConverter.StringToTextBinary);
+
nativeTypeMapping.AddDbTypeAlias("unknown", DbType.Object);
return nativeTypeMapping;
@@ -578,6 +582,10 @@ yield return
null,
BasicBackendToNativeTypeConverter.TextBinaryToString);
+ yield return new NpgsqlBackendTypeInfo(0, "hstore", NpgsqlDbType.Hstore, DbType.Object, typeof(String),
+ null,
+ BasicBackendToNativeTypeConverter.TextBinaryToString);
+
if (useExtendedTypes)
{
yield return
View
@@ -3889,10 +3889,7 @@ public void TestIEnumerableAsArray()
public void InsertJsonValueDataType()
{
if (Conn.PostgreSqlVersion < new Version(9, 2, 0))
- {
- // json data type is not supported prior to 9.2
- return;
- }
+ Assert.Ignore("json data type only introduced in 9.2");
var jsonValue = @"
{
@@ -3907,7 +3904,19 @@ public void InsertJsonValueDataType()
var result = cmd.ExecuteNonQuery();
Assert.AreEqual(1, result);
+ }
+ }
+ [Test]
+ public void InsertHstoreValueDataType()
+ {
+ if (Conn.PostgreSqlVersion < new Version(9, 1, 0))
+ Assert.Ignore("Loading the hstore extension in pre-9.1 is too complicated");
+ using (var cmd = new NpgsqlCommand("INSERT INTO data (field_hstore) VALUES (:param)", Conn))
+ {
+ cmd.Parameters.AddWithValue("param", @"""a"" => 3, ""b"" => 4");
+ cmd.Parameters[0].NpgsqlDbType = NpgsqlDbType.Hstore;
+ Assert.That(cmd.ExecuteNonQuery(), Is.EqualTo(1));
}
}
}
View
@@ -208,7 +208,6 @@ private void CreateSchema()
}
}
}
-
ExecuteNonQuery(@"CREATE TABLE data (
field_pk SERIAL PRIMARY KEY,
field_serial SERIAL,
@@ -237,6 +236,12 @@ private void CreateSchema()
field_circle CIRCLE
) WITH OIDS");
+ if (Conn.PostgreSqlVersion >= new Version(9, 1, 0))
+ {
+ ExecuteNonQuery(@"CREATE EXTENSION IF NOT EXISTS hstore");
+ ExecuteNonQuery(@"ALTER TABLE data ADD COLUMN field_hstore HSTORE");
+ }
+
if (Conn.PostgreSqlVersion >= new Version(9, 2, 0))
{
ExecuteNonQuery(@"ALTER TABLE data ADD COLUMN field_json JSON");

0 comments on commit 22e4fdb

Please sign in to comment.