sql:PostgreSQL
PostgreSQL sql script:
-- Database: geovindu -- DROP DATABASE geovindu; CREATE DATABASE geovindu
WITH OWNER = postgres
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'Chinese_People''s Republic of China.936'
LC_CTYPE = 'Chinese_People''s Republic of China.936'
CONNECTION LIMIT = -1; --创建表
create table BookKindList
(
BookKindID SERIAL PRIMARY KEY,
BookKindName varchar(500) not null,
BookKindCode varchar(100) null,
BookKindParent int null
); --查询
select * from BookKindList;
--添加
insert into BookKindList(BookKindName,BookKindParent) values('六福书目录',0); insert into BookKindList(BookKindName,BookKindParent) values('文学',1);
insert into BookKindList(BookKindName,BookKindParent) values('设计艺术',1);
insert into BookKindList(BookKindName,BookKindParent) values('自然科学',1); insert into BookKindList(BookKindName,BookKindParent) values('小说',2);
insert into BookKindList(BookKindName,BookKindParent) values('诗词散曲',2); select * from BookKindList where BookKindID=1;
--返回增加的ID
select lastval();
csharp:
/// <summary>
/// 涂聚文 20150212
/// PostgreSql添加返回值ID
/// </summary>
/// <param name="SQLString"></param>
/// <param name="identity"></param>
/// <param name="cmdParms"></param>
/// <returns></returns>
public static int ExecuteSql(string SQLString, out int identity, params NpgsqlParameter[] cmdParms)
{
string en = "";
using (NpgsqlConnection connection = new NpgsqlConnection(connectionString))
{
using (NpgsqlCommand cmd = new NpgsqlCommand())
{
try
{
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
int rows = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
cmd.CommandText = "select lastval();";
en = cmd.ExecuteScalar().ToString();
identity = int.Parse(en);
cmd.Parameters.Clear();
return rows;
}
catch (NpgsqlException E)
{
throw new Exception(E.Message);
}
}
}
} /// <summary>
/// 追回返回值
/// PostgreSql涂聚文
/// </summary>
/// <param name="bookKindList"></param>
/// <param name="id"></param>
/// <returns></returns>
public int InsertBookKindOut(BookKindListInfo bookKindList, out int id)
{
int ret = 0;
int tid = 0;
try
{
StringBuilder str = new StringBuilder();
str.Append("insert into BookKindList(BookKindName,BookKindCode,BookKindParent) values(");
str.Append("@BookKindName,@BookKindCode,@BookKindParent);");
NpgsqlParameter[] par = new NpgsqlParameter[]{
new NpgsqlParameter("@BookKindName",DbType.String,1000),
new NpgsqlParameter("@BookKindCode",DbType.String,1000),
new NpgsqlParameter("@BookKindParent",DbType.Int32,4),
//new NpgsqlParameter("@BookKindID",DbType.Int32,4),
};
par[0].Value = bookKindList.BookKindName;
par[1].Value = bookKindList.BookKindCode;
par[2].Value = bookKindList.BookKindParent;
//par[3].Direction = ParameterDirection.Output;//无效 不支持
ret = PostgreSqlHelper.ExecuteSql(str.ToString(), out tid, par);
if (ret > 0)
{
//tid = ret;// (int)par[3].Value;
}
}
catch (NpgsqlException ex)
{
throw ex;
}
id = tid; return ret;
}
sql:PostgreSQL的更多相关文章
- sql: postgreSQL sql script
SELECT * from pg_class c,pg_attribute a,pg_type t where c.relname='BookKindList' and a.attnum>0 a ...
- PostgreSQL的.NET驱动程序Npgsql
Npgsql是PostgreSQL的一个.NET数据提供程序,它可以自由获取.它可以通过下列选项获得独立的下载,也可以安装PostgreSQL数据库程序时选择安装. 最新的_npgsql2 Npgsq ...
- Fluent NHibernate and Mysql,SQLite,PostgreSQL
http://codeofrob.com/entries/sqlite-csharp-and-nhibernate.html https://code.google.com/archive/p/csh ...
- PostgreSQL pg_dump pg_dumpall and restore
pg_dump dumps a database as a text file or to other formats. Usage: pg_dump [OPTION]... [DBNAME] Gen ...
- PostgreSQL指南
PostgreSQL指南 历史简介 最近几年Postgres的关注度变得越来越高. 它加快了Postgres的发展步伐, 与此同时其他 的关系数据库系统的发展放缓. 在数据库领域中 Postgre S ...
- mysql+postgresql备份与恢复
mysql备份一个库, mysqldump -u用户名 -p密码 [选项] [数据库名] > /备份路径/备份文件名 mysqldump -uuser -p123123 auth > / ...
- How to make PostgreSQL functions atomic?
Question: How to make PostgreSQL functions atomic? Assume I have some PostgreSQL functions like the ...
- PostgreSQL 备份和恢复
备份和恢复有三种不同的基本方法来备份PostgreSQL数据SQL转储文件系统级备份File system level backup连续归档 1. SQL转储 pg_dump dbname > ...
- PostgreSQL 二进制安装
一.安装前准备工作 新建用户 sudo groupadd sql sudo useradd -g sql postgressudo passwd postgres 创建数据及日志目录,并做相应授权 s ...
随机推荐
- 在IDEA中 SFTP 进行发布操作
1, 2, 3, 4, 成功了 补充:] 也可以使用手动写配置文件的方式来的
- string、char *的转换
string转char* 主要有三种方法可以将str转换为char*类型,分别是:data(); c_str(); copy(); data()方法 string str = "hello& ...
- 并发编程>>四种实现方式(三)
概述 1.继承Thread 2.实现Runable接口 3.实现Callable接口通过FutureTask包装器来创建Thread线程 4.通过Executor框架实现多线程的结构化,即线程池实现. ...
- panda的query过滤
pandas中可以用query函数以类SQL语言执行查询.
- 数组或者stack
数组 clear1(long long int array[], size_t int size) { ; i < size; i += ) array[i] = ; } li x5, // i ...
- Mono For Android中完美使用百度地图SDK(v2.1.2&v2.1.3)(转)
在Xamarin Mono For Android的开发中,如果要使用第三方的jar,就必须进行绑定.通过创建Java Bindings Library项目来自动生成C#到java的代码映射代码,最终 ...
- 重签名android测试包
我的一个例子:jarsigner -digestalgSHA1 -sigalg MD5withRSA -keystore C:\Users\sunyang\.android\debug.keystor ...
- PHP之string之ord()函数使用
ord (PHP 4, PHP 5, PHP 7) ord - Return ASCII value of character ord - 返回字符的 ASCII 码值 Description int ...
- *2.2.3 加入objection机制
在上一节中,虽然输出了“main_phase is called”,但是“data is drived”并没有输出.而main_phase是一个完整的任务,没有理由只执行第一句,而后面的代码不执行.看 ...
- python实例:在列表,字典,集合中,根据条件筛选数据
1. 从列表中过滤掉 负数 from random import randint # 随机生成列表 data = [randint(-10, 10) for _ in range(10)] print ...