本文整理汇总了C#中Npgsql.NpgsqlParameter类的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlParameter类的具体用法?C# NpgsqlParameter怎么用?C# NpgsqlParameter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NpgsqlParameter类属于Npgsql命名空间,在下文中一共展示了NpgsqlParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteByModule
public static bool DeleteByModule(int moduleId)
{
StringBuilder sqlCommand = new StringBuilder();
sqlCommand.Append("DELETE FROM mp_mediafile ");
sqlCommand.Append("WHERE ");
sqlCommand.Append("fileid ");
sqlCommand.Append("IN (");
sqlCommand.Append("SELECT fileid FROM mp_mediafile WHERE trackid IN (");
sqlCommand.Append("SELECT trackid FROM mp_mediatrack WHERE playerid IN (");
sqlCommand.Append("SELECT playerid FROM mp_mediaplayer WHERE moduleid = :moduleid");
sqlCommand.Append(")");
sqlCommand.Append(")");
sqlCommand.Append(")");
sqlCommand.Append(";");
NpgsqlParameter[] arParams = new NpgsqlParameter[1];
arParams[0] = new NpgsqlParameter("moduleid", NpgsqlTypes.NpgsqlDbType.Integer);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = moduleId;
int rowsAffected = NpgsqlHelper.ExecuteNonQuery(
ConnectionString.GetWriteConnectionString(),
CommandType.Text,
sqlCommand.ToString(),
arParams);
return (rowsAffected > -1);
}
示例2: Range
public void Range()
{
using (var conn = OpenConnection())
using (var cmd = new NpgsqlCommand("SELECT @p1, @p2, @p3, @p4", conn))
{
var p1 = new NpgsqlParameter("p1", NpgsqlDbType.Range | NpgsqlDbType.Integer) { Value = NpgsqlRange<int>.Empty() };
var p2 = new NpgsqlParameter { ParameterName = "p2", Value = new NpgsqlRange<int>(1, 10) };
var p3 = new NpgsqlParameter { ParameterName = "p3", Value = new NpgsqlRange<int>(1, false, 10, false) };
var p4 = new NpgsqlParameter { ParameterName = "p4", Value = new NpgsqlRange<int>(0, false, true, 10, false, false) };
Assert.That(p2.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Range | NpgsqlDbType.Integer));
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
cmd.Parameters.Add(p3);
cmd.Parameters.Add(p4);
using (var reader = cmd.ExecuteReader())
{
reader.Read();
Assert.That(reader[0].ToString(), Is.EqualTo("empty"));
Assert.That(reader[1].ToString(), Is.EqualTo("[1,11)"));
Assert.That(reader[2].ToString(), Is.EqualTo("[2,10)"));
Assert.That(reader[3].ToString(), Is.EqualTo("(,10)"));
}
}
}
示例3: CreatePath
public static Guid CreatePath(int siteId, String path)
{
Guid newPathID = Guid.NewGuid();
NpgsqlParameter[] arParams = new NpgsqlParameter[4];
arParams[0] = new NpgsqlParameter("pathid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = newPathID;
arParams[1] = new NpgsqlParameter("siteid", NpgsqlTypes.NpgsqlDbType.Integer);
arParams[1].Direction = ParameterDirection.Input;
arParams[1].Value = siteId;
arParams[2] = new NpgsqlParameter("path", NpgsqlTypes.NpgsqlDbType.Varchar, 255);
arParams[2].Direction = ParameterDirection.Input;
arParams[2].Value = path;
arParams[3] = new NpgsqlParameter("loweredpath", NpgsqlTypes.NpgsqlDbType.Varchar, 255);
arParams[3].Direction = ParameterDirection.Input;
arParams[3].Value = path.ToLower();
NpgsqlHelper.ExecuteNonQuery(
ConnectionString.GetWriteConnectionString(),
CommandType.StoredProcedure,
"mp_sitepaths_insert(:pathid,:siteid,:path,:loweredpath)",
arParams);
return newPathID;
}
示例4: Bug1011018
public void Bug1011018()
{
var p = new NpgsqlParameter();
p.NpgsqlDbType = NpgsqlDbType.Time;
p.Value = DateTime.Now;
Object o = p.Value;
}
示例5: AddUser
public static bool AddUser(
int roleId,
int userId,
Guid roleGuid,
Guid userGuid
)
{
NpgsqlParameter[] arParams = new NpgsqlParameter[4];
arParams[0] = new NpgsqlParameter("roleid", NpgsqlTypes.NpgsqlDbType.Integer);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = roleId;
arParams[1] = new NpgsqlParameter("userid", NpgsqlTypes.NpgsqlDbType.Integer);
arParams[1].Direction = ParameterDirection.Input;
arParams[1].Value = userId;
arParams[2] = new NpgsqlParameter("roleguid", NpgsqlTypes.NpgsqlDbType.Char, 36);
arParams[2].Direction = ParameterDirection.Input;
arParams[2].Value = roleGuid.ToString();
arParams[3] = new NpgsqlParameter("userguid", NpgsqlTypes.NpgsqlDbType.Char, 36);
arParams[3].Direction = ParameterDirection.Input;
arParams[3].Value = userGuid.ToString();
int rowsAffected = Convert.ToInt32(NpgsqlHelper.ExecuteScalar(
ConnectionString.GetWriteConnectionString(),
CommandType.StoredProcedure,
"mp_userroles_insert(:roleid,:userid,:roleguid,:userguid)",
arParams));
return (rowsAffected > -1);
}
示例6: Constructor1
public void Constructor1()
{
var p = new NpgsqlParameter();
Assert.AreEqual(DbType.String, p.DbType, "DbType");
Assert.AreEqual(ParameterDirection.Input, p.Direction, "Direction");
Assert.IsFalse(p.IsNullable, "IsNullable");
#if NET_2_0
//Assert.AreEqual (0, p.LocaleId, "LocaleId");
#endif
Assert.AreEqual(string.Empty, p.ParameterName, "ParameterName");
Assert.AreEqual(0, p.Precision, "Precision");
Assert.AreEqual(0, p.Scale, "Scale");
Assert.AreEqual(0, p.Size, "Size");
Assert.AreEqual(string.Empty, p.SourceColumn, "SourceColumn");
#if NET_2_0
Assert.IsFalse(p.SourceColumnNullMapping, "SourceColumnNullMapping");
#endif
Assert.AreEqual(DataRowVersion.Current, p.SourceVersion, "SourceVersion");
Assert.AreEqual(NpgsqlDbType.Text, p.NpgsqlDbType, "NpgsqlDbType");
#if NET_2_0
Assert.IsNull(p.NpgsqlValue, "NpgsqlValue");
#endif
Assert.IsNull(p.Value, "Value");
#if NET_2_0
//Assert.AreEqual (string.Empty, p.XmlSchemaCollectionDatabase, "XmlSchemaCollectionDatabase");
//Assert.AreEqual (string.Empty, p.XmlSchemaCollectionName, "XmlSchemaCollectionName");
//Assert.AreEqual (string.Empty, p.XmlSchemaCollectionOwningSchema, "XmlSchemaCollectionOwningSchema");
#endif
}
示例7: Insert
public NpgQuery Insert(string table, string[] columns, IEnumerable<object[]> values)
{
var valuesArray = values as object[][] ?? values.ToArray();
var parameters = new NpgsqlParameter[columns.Length * valuesArray.Count()];
var insertDataScript = new string[valuesArray.Count()];
var parametersIndex = 0;
for (var i = 0; i < valuesArray.Length; i++)
{
var i1 = i;
insertDataScript[i] = string.Format(
"({0})",
string.Join(", ", columns.Select(c => string.Format(":{0}", c + i1))));
var data = valuesArray[i];
for (var j = 0; j < columns.Length; j++)
{
var column = columns[j];
var value = data[j];
parameters[parametersIndex++] = new NpgsqlParameter(column + i1, value);
}
}
var scriptRow = string.Format(
"INSERT INTO {0} ({1}) VALUES {2}",
Quote(table),
string.Join(", ", columns.Select(Quote)),
string.Join(", ", insertDataScript));
return new NpgQuery(scriptRow, parameters);
}
示例8: GetDataTable
public DataTable GetDataTable(string command, NpgsqlParameter [] parameters)
{
DataTable dt;
Console.WriteLine(parameters[0].Value);
dt = SqlHelper.ExecuteDataTable(this.ConnectionString, CommandType.StoredProcedure, command, parameters);
return dt;
}
示例9: Create
/// <summary>
/// Inserts a row in the mp_TaxClass table. Returns rows affected count.
/// </summary>
/// <param name="guid"> guid </param>
/// <param name="siteGuid"> siteGuid </param>
/// <param name="title"> title </param>
/// <param name="description"> description </param>
/// <param name="lastModified"> lastModified </param>
/// <param name="created"> created </param>
/// <returns>int</returns>
public static int Create(
Guid guid,
Guid siteGuid,
string title,
string description,
DateTime lastModified,
DateTime created)
{
NpgsqlParameter[] arParams = new NpgsqlParameter[6];
arParams[0] = new NpgsqlParameter("guid", NpgsqlTypes.NpgsqlDbType.Char, 36);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = guid.ToString();
arParams[1] = new NpgsqlParameter("siteguid", NpgsqlTypes.NpgsqlDbType.Char, 36);
arParams[1].Direction = ParameterDirection.Input;
arParams[1].Value = siteGuid.ToString();
arParams[2] = new NpgsqlParameter("title", NpgsqlTypes.NpgsqlDbType.Varchar, 255);
arParams[2].Direction = ParameterDirection.Input;
arParams[2].Value = title;
arParams[3] = new NpgsqlParameter("description", NpgsqlTypes.NpgsqlDbType.Text);
arParams[3].Direction = ParameterDirection.Input;
arParams[3].Value = description;
arParams[4] = new NpgsqlParameter("lastmodified", NpgsqlTypes.NpgsqlDbType.Timestamp);
arParams[4].Direction = ParameterDirection.Input;
arParams[4].Value = lastModified;
arParams[5] = new NpgsqlParameter("created", NpgsqlTypes.NpgsqlDbType.Timestamp);
arParams[5].Direction = ParameterDirection.Input;
arParams[5].Value = created;
StringBuilder sqlCommand = new StringBuilder();
sqlCommand.Append("INSERT INTO mp_taxclass (");
sqlCommand.Append("guid, ");
sqlCommand.Append("siteguid, ");
sqlCommand.Append("title, ");
sqlCommand.Append("description, ");
sqlCommand.Append("lastmodified, ");
sqlCommand.Append("created )");
sqlCommand.Append(" VALUES (");
sqlCommand.Append(":guid, ");
sqlCommand.Append(":siteguid, ");
sqlCommand.Append(":title, ");
sqlCommand.Append(":description, ");
sqlCommand.Append(":lastmodified, ");
sqlCommand.Append(":created ");
sqlCommand.Append(")");
sqlCommand.Append(";");
int rowsAffected = NpgsqlHelper.ExecuteNonQuery(ConnectionString.GetWriteConnectionString(),
CommandType.Text,
sqlCommand.ToString(),
arParams);
return rowsAffected;
}
示例10: Add
public static int Add(
Guid guid,
Guid siteGuid,
string folderName)
{
NpgsqlParameter[] arParams = new NpgsqlParameter[3];
arParams[0] = new NpgsqlParameter("guid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = guid.ToString();
arParams[1] = new NpgsqlParameter("siteguid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[1].Direction = ParameterDirection.Input;
arParams[1].Value = siteGuid.ToString();
arParams[2] = new NpgsqlParameter("foldername", NpgsqlTypes.NpgsqlDbType.Varchar, 255);
arParams[2].Direction = ParameterDirection.Input;
arParams[2].Value = folderName;
int rowsAffected = NpgsqlHelper.ExecuteNonQuery(ConnectionString.GetWriteConnectionString(),
CommandType.StoredProcedure,
"mp_sitefolders_insert(:guid,:siteguid,:foldername)",
arParams);
return rowsAffected;
}
示例11: AdjustTrackOrdersForDelete
/// <summary>
/// Updates the TrackOrder values for the tracks that remain for the PlayerID by incrementing any Tracks that have a TrackOrder value
/// greater than the provided trackOrder.
/// </summary>
/// <param name="playerID">The ID of the Player.</param>
/// <param name="trackOrder">The TrackOrder value.</param>
/// <returns>The number of rows affected by the update.</returns>
public static int AdjustTrackOrdersForDelete(int playerId, int trackOrder)
{
StringBuilder sqlCommand = new StringBuilder();
sqlCommand.Append("UPDATE mp_mediatrack ");
sqlCommand.Append("SET trackorder = trackorder - 1 ");
sqlCommand.Append("WHERE ");
sqlCommand.Append("playerid = :playerid ");
sqlCommand.Append("AND trackorder > :trackorder ");
sqlCommand.Append(";");
NpgsqlParameter[] arParams = new NpgsqlParameter[2];
arParams[0] = new NpgsqlParameter("playerid", NpgsqlTypes.NpgsqlDbType.Integer);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = playerId;
arParams[1] = new NpgsqlParameter("trackorder", NpgsqlTypes.NpgsqlDbType.Integer);
arParams[1].Direction = ParameterDirection.Input;
arParams[1].Value = trackOrder;
int rowsAffected = NpgsqlHelper.ExecuteNonQuery(
ConnectionString.GetWriteConnectionString(),
CommandType.Text,
sqlCommand.ToString(),
arParams);
return rowsAffected;
}
示例12: AmbiguousFunctionParameterType
public void AmbiguousFunctionParameterType()
{
ExecuteNonQuery(@"CREATE OR REPLACE FUNCTION ambiguousParameterType(int2, int4, int8, text, varchar(10), char(5)) returns int4 as '
select 4 as result;
' language 'sql'");
//NpgsqlConnection conn = new NpgsqlConnection(ConnectionString);
NpgsqlCommand command = new NpgsqlCommand("ambiguousParameterType(:a, :b, :c, :d, :e, :f)", Conn);
command.CommandType = CommandType.StoredProcedure;
NpgsqlParameter p = new NpgsqlParameter("a", DbType.Int16);
p.Value = 2;
command.Parameters.Add(p);
p = new NpgsqlParameter("b", DbType.Int32);
p.Value = 2;
command.Parameters.Add(p);
p = new NpgsqlParameter("c", DbType.Int64);
p.Value = 2;
command.Parameters.Add(p);
p = new NpgsqlParameter("d", DbType.String);
p.Value = "a";
command.Parameters.Add(p);
p = new NpgsqlParameter("e", NpgsqlDbType.Char);
p.Value = "a";
command.Parameters.Add(p);
p = new NpgsqlParameter("f", NpgsqlDbType.Varchar);
p.Value = "a";
command.Parameters.Add(p);
command.ExecuteScalar();
}
示例13: ImplicitSettingOfDbTypes
public void ImplicitSettingOfDbTypes()
{
var p = new NpgsqlParameter("p", DbType.Int32);
Assert.That(p.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Integer));
// As long as NpgsqlDbType/DbType aren't set explicitly, infer them from Value
p = new NpgsqlParameter("p", 8);
Assert.That(p.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Integer));
Assert.That(p.DbType, Is.EqualTo(DbType.Int32));
p.Value = 3.0;
Assert.That(p.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Double));
Assert.That(p.DbType, Is.EqualTo(DbType.Double));
p.NpgsqlDbType = NpgsqlDbType.Bytea;
Assert.That(p.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Bytea));
Assert.That(p.DbType, Is.EqualTo(DbType.Binary));
p.Value = "dont_change";
Assert.That(p.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Bytea));
Assert.That(p.DbType, Is.EqualTo(DbType.Binary));
p = new NpgsqlParameter("p", new int[0]);
Assert.That(p.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Array | NpgsqlDbType.Integer));
Assert.That(p.DbType, Is.EqualTo(DbType.Object));
}
示例14: CreatePersonalizationBlob
public static void CreatePersonalizationBlob(
Guid userGuid,
Guid pathId,
byte[] dataBlob,
DateTime lastUpdateTime)
{
NpgsqlParameter[] arParams = new NpgsqlParameter[5];
arParams[0] = new NpgsqlParameter("id", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = Guid.NewGuid().ToString();
arParams[1] = new NpgsqlParameter("userid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[1].Direction = ParameterDirection.Input;
arParams[1].Value = userGuid.ToString();
arParams[2] = new NpgsqlParameter("pathid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[2].Direction = ParameterDirection.Input;
arParams[2].Value = pathId.ToString();
arParams[3] = new NpgsqlParameter("pagesettings", NpgsqlTypes.NpgsqlDbType.Bytea);
arParams[3].Direction = ParameterDirection.Input;
arParams[3].Value = dataBlob;
arParams[4] = new NpgsqlParameter("lastupdate", NpgsqlTypes.NpgsqlDbType.Timestamp);
arParams[4].Direction = ParameterDirection.Input;
arParams[4].Value = lastUpdateTime;
NpgsqlHelper.ExecuteNonQuery(
ConnectionString.GetWriteConnectionString(),
CommandType.StoredProcedure,
"mp_sitepersonalizationperuser_insert(:id,:userid,:pathid,:pagesettings,:lastupdate)",
arParams);
}
示例15: GetSiteSettingsExList
public DbDataReader GetSiteSettingsExList(int siteId)
{
StringBuilder sqlCommand = new StringBuilder();
sqlCommand.Append("SELECT e.* ");
sqlCommand.Append("FROM mp_sitesettingsex e ");
sqlCommand.Append("JOIN ");
sqlCommand.Append("mp_sitesettingsexdef d ");
sqlCommand.Append("ON ");
sqlCommand.Append("e.keyname = d.keyname ");
sqlCommand.Append("AND e.groupname = d.groupname ");
sqlCommand.Append("WHERE ");
sqlCommand.Append("e.siteid = :siteid ");
sqlCommand.Append("ORDER BY d.groupname, d.sortorder ");
sqlCommand.Append(";");
NpgsqlParameter[] arParams = new NpgsqlParameter[1];
arParams[0] = new NpgsqlParameter("siteid", NpgsqlTypes.NpgsqlDbType.Integer);
arParams[0].Value = siteId;
return AdoHelper.ExecuteReader(
readConnectionString,
CommandType.Text,
sqlCommand.ToString(),
arParams);
}