xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 0.34M
    文件類型: .pdf
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-03-27
  • 語言: 數(shù)據(jù)庫
  • 標(biāo)簽: sql??

資源簡介


Npgsql User Manual Npgsql用戶使用手冊(cè)-簡體中文版 100%由原官方文檔翻譯。
<@ Assembly name="System. Data"2> <s@ Assembly name="Npgsql"8> 你可以從這里獲得更多的細(xì)節(jié) FAQ Mono Page about ASP. NET 建立連接 使用名為“joe”密碼為“ secret”的用戶,建立一個(gè)到IP地址為127.0.0.1,端∏為5432的服務(wù)器上的“ joedata”的數(shù)據(jù)庫的連接,可以使 用以下的連接字符串來打開 NpgsqlConnection。 using system; using system. Data using Pgsql public class NpgsqlUserManual public static void Main(String[] args) NpgsqlCo nection Con Npgsq-Connection ("Server=127.0.0. 1i Port=5432; User Id=joe; Password=secret; Database=joedata: )i con Cpen() co'n Close() 連接字符串里的參數(shù) 建立連接的時(shí)候, Npgsql Connection可以接受一些用以改變其行為的參數(shù),下面就是現(xiàn)在你可以使用的參數(shù)列表:(溟自 NpgsqlConnection 的源代碼) 連接 PostgreSQL數(shù)據(jù)厙時(shí),可以獲取或者設(shè)置這些字符串。合法的值有: Server PostgresQL服務(wù)器的IP地或名字 Por 用以連接的端口 Protocol 使用的協(xié)議版本,可以用 Integer類型的2或者3代替 automatic Database 數(shù)據(jù)庫名字,如果沒有指定,默認(rèn)為與用戶名相同 User id 用尸名 Integrated Security 設(shè)置為 Windows集成安全性,默認(rèn)為fase Password 純文本的身份驗(yàn)證密碼 SSL True或者 False,控制是否使用一個(gè)安全的連接(SSL連接),默認(rèn)為 false Poolin True或者 False,控制是否使用連孌池,默認(rèn)為True Minpoolsize 連接淝的最小值,指定了連接池的最小值,可以讓 Npgsqlo。 nnection預(yù)冗分酎指定數(shù)量的連接。默認(rèn)值為1 Maxpoolsize 迕接池的最大值,如果迄接氿內(nèi)的連接的數(shù)量大亍這個(gè)值,那么堵塞的連接將被處置掉。默認(rèn)值為:20 Encoding 已廢弁。總是返回“ Unicode”字符串,即使設(shè)置它也會(huì)被忽略 Timeout 等待連接的事件,單位為秒。默認(rèn)值為:15 Commandtimeout 等待命令完成執(zhí)行的時(shí)間,超時(shí)將拋出異常。單位為秒。默認(rèn)值為:20 Sslmode 連接控制的方式,可以是以下值中的一個(gè) Prefer 如果有可能使用SSL連接,那么就采用SSL連接。(首選) Require 如果不能建立SSL連接,將拋出異常。(必須) AllOw 如果還不支持,那么就使用非SSL連接。(允許 Disable 使用非SSL連接(不允許) 默認(rèn)值是“ Disable” Connectional fetime 連接池中不再使用的連接關(guān)閉的等待時(shí)間。單位:秒,默認(rèn)值為:15 SyncNotification 指定的話 Npgsq將使用同步消息機(jī)制 SearchPath 改變 public的和特定的模式的搜索路徑 Pre⊥ oad reade 如果設(shè)置為為“‘true”〔默認(rèn)值為“ false”)的活,數(shù)據(jù)讀取器寢在 Executerεder全部返回前被加載。這將尋致性能損失(特別是在大量的記 錄集時(shí),可能導(dǎo)致不可容忍的性能損失〕,它保留下來是為了和之前版本的 Pgsql保持兼容。根據(jù)ADO.N氏T文檔,當(dāng) I DataReader打開用于 獲取數(shù)據(jù)的 IDbConnection時(shí),它的狀態(tài)被設(shè)置為“busy”,不能用于其他任何操作(有一些明確的異常( Exception類)專門針對(duì)此規(guī)則) Npgsa強(qiáng)制執(zhí)行這個(gè)規(guī)則,所以當(dāng) Npgsa| Datareader打開后,其他的基于這個(gè)用于獲取數(shù)據(jù)的 IDbConnection上的其它操作都將導(dǎo)致 InvalidOperationEⅹ ception( Pgsql放松了這個(gè)規(guī)則,如果 Npgsq| DataReader已經(jīng)讀到結(jié)果集的結(jié)尾但是還沒有破關(guān)閉, Pgsql允午你使 用這個(gè)連接。因?yàn)檫@時(shí),它不再從迕接上使用什么資源。) 但是左以前, Npgsq允許用戶完全忽賂這個(gè)規(guī)則。這完全是一個(gè)內(nèi)置的執(zhí)行問題的副作用,嚴(yán)格來說,它從來沒有被支捋過(因?yàn)樗偸沁`背 AD◎.NET的規(guī)范),而且這一點(diǎn)偷懶可能會(huì)讓你發(fā)現(xiàn)以前運(yùn)行良好的代碼突然掛掉了。如果你確定無論如何都要使用它,可以將它作為修復(fù)代碼 前的權(quán)益之計(jì),基于下兩個(gè)原因: 性能,尤其是可伸縮性,不適用這個(gè)選項(xiàng)仲縮性將更好 Use Extended Types 這個(gè)選項(xiàng)可決定 Data Adaptors到底是使用NET的 System Data Time類型還是使用類似 NpgsqlTimestamp這樣比 System Data Time類 型具有更多功能和使用范圍的 Npgsq的日期和事件類型。選項(xiàng)設(shè)置為“ Either”允許使用 Pgsql和 System類型,但是如果設(shè)置為“true” DataAdaptors將考慮為字段仗用使用定的 Npgsq類型,反之,如果設(shè)置為“ false”將使用 Systen. Data time 這個(gè)選項(xiàng)是實(shí)驗(yàn)性的,有可能因?yàn)闆_突在新版本中簡化或刪掉 默認(rèn)值為“ false Compatibility 這個(gè)版本的目的是為了應(yīng)付不斷曾加新的連接字符串選項(xiàng)而帶來的破壞性的變更,它的值可以設(shè)置為版本號(hào)的形式(像這樣a.b[.cC[C]).變化 可能會(huì)破壞現(xiàn)有的代碼,所以,在可能的情況下,盡量復(fù)制以前版本的行為。第一個(gè)這么做的版本是2.0.2.1,所以在2.0.2中,這個(gè)值不會(huì)有新 的行為。 版本行為 如果指定字段名找不到,則Ge0 rinal返回-1 0.2 etOrdinal區(qū)分假名的寬度 版本行為 口果指定字段名找不到,則 Getordinal將拋出 IndexOutOfRange Exception異常 0.2.1 GetOrdinal不區(qū)分假名寬度 使用 Npgsql Command向表格增加一個(gè)行 前面的示例其實(shí)一點(diǎn)有用的事情也沒有做,僅僅是連接效據(jù)庫,然后斷開。如果有錯(cuò)誤的話,將拋出一個(gè) Npgsq| Exception異常。現(xiàn)在假設(shè)你有 一個(gè)名為“ table1”的表,該表恪捐有“ fielda”和“ field”兩個(gè)字段,類型都是int.如果你想向該表格屮插入(1,1)元組,可以使用以下插入 語句。 using system; using system. Datai using Npgsq public static class NpgsqlUserManual public static void Main(String[ args) NpgsqlConnection Npgsq-Connection("server=127.0.0.liport=5432 User Id=joe; Password=secreti Database=joedata; coIn. Cpe1(): NpgsqlCommand command= new NpgsqlCommand(insert into tablel values(1, 1)", conn); Int32 rows. ffected trv rowsaffected= command. ExecuteNonQuery()i Console. WriteLine("It was added o lines in table tablel" rowsaffected) finally n Close ExecuteNonQuery()是插入和更新查詢的理想方法,囚為它返回一個(gè)指小受最后一次操作影響的行數(shù)的整數(shù)。 使用 NpgsqlCommand. EXecute Scalar()方法獲取單一的返回值 有些情況下,你只想從函數(shù)取回會(huì)一個(gè)單獨(dú)的值( scalar)這是你可以使用 Command對(duì)象的 Executescalar()方法。 usIng System. Dat. using Pgsql public static class Npgsq-UserManual { public static voi NpgsqIConnection co-n ne Npgsg-Connection("server=127.0.0. liport=5432; User Id=joe; Password=secreti Database=joedata: co-n Cpe(): Npgsql Comma nd command new NpgsqlCommand("select. version(),conn)i string serverversion; try serverversion=(String)command. ExecuteScalar()i Console. WriteLine('EostgresQ- server version: [0], serverversicn)i finally y conn Close(i 你也可以使用 Executescalar執(zhí)行返回記錄集的查詢,比如“ select count(*) from table1”。但是,當(dāng)調(diào)用返回一條或更多記錄的函數(shù)時(shí) 只有第一行的第一列能這回(目 Dataset. Tables[0].Rows[o][0])。一股來說,何一個(gè)返回單一值的香詢都應(yīng)該使 Command ExecuteScalar 使用 Npgsqlcommand ExecuteReader()方法和 Npgsql DataReader獲得完整的結(jié)果集 有很多方式可以獲得 Pgsql返回的記錄集。當(dāng)你想通過一個(gè)sQL語句作為命令的文本和使用高效內(nèi)存數(shù)據(jù)讀取器訪問結(jié)果的時(shí)候,請(qǐng)使用 Npgsglcommand對(duì)象的 EXecuteReader()方法。 using system; using system. Data using Pgsql oublic static class NpgsqlUserManual public static void Main(String[] args) Npgsql Connection Npgsq Connection ("Server=127.0.0. 1 i Port=5432: User Id=joei Password=secreti Database=joedata; )i co-n. cpe NpgsqlCommand command new Npg sqlCommand("select x from tablea, conn)i NpgsglDataReader dr= command. ExecuteReader()i while(dr Read() Tor ( dr. Field i++) insole Write("[0)t", dr[il tinally conn Close()i 記住,你可以在一個(gè) Command對(duì)象的 CommandText屬性中使用一連串的 select語句來檢索多余一個(gè)的記錄集,就像這樣:“ select*from ta blea select k from tableb 在查詢中使用參數(shù) 參數(shù)可以讓你在運(yùn)行時(shí)動(dòng)態(tài)的向SQL查詢中插入多個(gè)值,一般而言,參數(shù)綁定是你在客戶端代碼中產(chǎn)生動(dòng)態(tài)SQL語句的最好方法。而其他的方法, 如基本的串聯(lián)宇符串的方?jīng)V,是不太可靠的,它可能會(huì)招致注入攻擊。通過在參數(shù)名稱前附加“:”前綴的方式同你的SQL查詢字符串中增加參 數(shù)。下面的示例使用一個(gè)名為“vaue1”的參數(shù)(就像這樣“:vaue1”) using system stem. Dat using Pgsql public static class NpgsqlUserManual public static void Main (String[] args) using(NpgsqlConnection conn Npgsq-Connection ("Server=127,0.0. li Port=5432: User Id=joe: Password=secret Database=joedata: ") conn Cpen()i /聲明查詢語句中使用的參數(shù) using(Npgsq l Commandcommand= rew Npgsgl Command('select s from tablea where colurmr1=: va luel", conn)) Now add the parameter to the parameter collection of the command specifying its type ∥/垗在按照參數(shù)的類型將參教添加到參數(shù)集合中。 command. Pa rameters. Add(new Pgsql Parameter("valuel", Pgsql DbType Integer)) /7 Now, add a value to it and later execute the command as usual /現(xiàn)在,設(shè)置參數(shù)的值,并在稍后執(zhí)行查詢。 command Parameters[ ol Value 4 using(NpgsqlDataReader dr command ExecuteReader()) while(dr Read( i=0: i dr. Fieldcount i++ Console. Write("(0\t", dr[i]); Console. Writeine(i 你也可以使用 Pgsql Parameter和 Npgsql Parameter collection對(duì)象向服務(wù)器發(fā)送一個(gè)參數(shù)化的查詢 這段代碼假設(shè)已存在一個(gè)名為“ tablea”的表,且它至少有一個(gè)名為“ column1”類型為int4的字段 使用預(yù)備語句 預(yù)備語句可以優(yōu)化你經(jīng)常使用的查詢的性能, Prepare()基本上就是“緩存”的查詢計(jì)劃,這樣就可以在以后的調(diào)用使用它。(記住:這個(gè)特性只 能在73以后的版本中使冂,如果你在一個(gè)不支持它的服務(wù)器中使用它, Npgsq將悄悄的忽略它)在執(zhí)行查詢之前簡單的調(diào)用 NpgsqlCommand 的 Prepare(方法就可以了。 using system. Datai ng Rpgs public static class NpgsalUserManual public static void Main(String args) using(pgsglConnection conn new Npgsg-Connection ("server=127.0.0. li port=5432; User Id=joe: Password=secreti Database=joedata: ) conn Cpen()i //在查詢語句中言明參數(shù) using(NpgsqlCommand command=new NpgsalCommand("select from ablea where column1=: colannl", conn)) //現(xiàn)在,把參數(shù)添加到合令的參數(shù)集合中,并指定其類型 command Parameters. Add(new NpgsqlParameter ("columnl", Npg sqlDbType. Irtecer) //現(xiàn)在,預(yù)各這個(gè)命令 //現(xiàn)在,給參數(shù)添加一個(gè)值,并在梢后像普通方式一樣執(zhí)行這個(gè)命令 command Parameters[o.value 4 using(NpgsqlDataReader dr= command. ExecuteReader()) while(dr Read ()i for (1=0: i< dr. Fieldcount; i++ Console. Write("(o\t", dr[i])i onsale. Writeine(i 這段代碼假定已存在一個(gè)名為“ tablea”的表,且它至少有個(gè)一個(gè)名為“ column1”類型為int4的字段。 函數(shù)調(diào)用 要調(diào)用函數(shù),需要將 Npgsqlcommand對(duì)象的 CommandType屬性設(shè)置為 CommandType StoredProcedure,并將你要調(diào)用的函數(shù)名作為 杳詢字符串(在 CommandTex屬性設(shè)置杳詢字符申) 譯者注:因?yàn)?Npgsq中標(biāo)識(shí)符是區(qū)分大小寫的,所以,如果你的函數(shù)名中有大小寫,需要將函數(shù)名用雙引號(hào)括起來,比如: command. Commandtext="" getTableName\",這樣實(shí)際上發(fā)送給服務(wù)器的函數(shù)名字外就有雙引號(hào)了。 using System. using system. Datai using pgsql //這個(gè)示例使用一個(gè)名為〃 funct()〃的函數(shù),它的定義如下 / create function funct() returns inte as / select count(x) from tablea; t language Note that the return type of select count (* changed from int4 to inc8 in 7.3+ versions. To use this function /7 in a 7. 2 server, change the return type from int8 to int 4 //注意:在7.3以前的阪本中, select ccu(*)將int4類型轉(zhuǎn)換為int8類型,如果要在7.2版本中使用,需要將int8轉(zhuǎn)化為int4類型 public static class NpgsqlUserManual public static void Main(String[] args) NpgsqlConnection Npgsq-Connection("server=127.0.0. liPort=5432i User Id=joe; Password=secret; Database=joedata: )i con. Cpen(): NpgsqlCommanc command new NpgsqlCommand("funct", conn) corman. CommandType= CommandType StoredProcedure Object result command Executescalar()i Console. Writeline(result) fia1⊥ onn. Close(i 向 PostgreSQL増加參數(shù)很像我們前面的小例。不過,當(dāng)我們指定 CommandText字符串的時(shí)侯,可以省略參數(shù)的名字,只使用函數(shù)名字就可以 using system using System. Datai using Npgsali / This example uses a function called funcc with the =ollowing definitio //create function funcc(int. 4) returns int8 as / select count(x) from tablea where field int4 = $li //1 anguage'sq1'’; public static class NpgsqlUserManual public static void Main(String[] args) NpgsqlConnection conn Ipgsq-Connection ("Server=127 1, port=5232: User Id-joei Password-secreti Database-joedatai")i co n Cpe (i tr NpgsqlCommand command= new NpgsglCommand("funcc", conn)i conman. CommandType CommandType storedProcedurei command. aranecers Add (new Npgscl Parameter() command ?=.0]. Npgsql DbType- NpgsqlDbType Integer command. aranmesers0] Value 4; object result= command. F. xecutescalar( Console. Writeline(result)i

資源截圖

代碼片段和文件信息

評(píng)論

共有 條評(píng)論