⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbi.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 5 页
字号:
\&            or die $DBI::errstr;\&  $dbh = DBI\->connect_cached($data_source, $username, $password, \e%attr)\&            or die $DBI::errstr;.Ve.PP\&\f(CW\*(C`connect_cached\*(C'\fR is like \*(L"connect\*(R", except that the database handlereturned is alsostored in a hash associated with the given parameters. If another callis made to \f(CW\*(C`connect_cached\*(C'\fR with the same parameter values, then thecorresponding cached \f(CW$dbh\fR will be returned if it is still valid.The cached database handle is replaced with a new connection if ithas been disconnected or if the \f(CW\*(C`ping\*(C'\fR method fails..PPThat the behaviour of this method differs in several respects from thebehaviour of persistent connections implemented by Apache::DBI.However, if Apache::DBI is loaded then \f(CW\*(C`connect_cached\*(C'\fR will use it..PPCaching connections can be useful in some applications, but it canalso cause problems, such as too many connections, and so shouldbe used with care. In particular, avoid changing the attributes ofa database handle created via \fIconnect_cached()\fR because it will affectother code that may be using the same handle..PPWhere multiple separate parts of a program are using \fIconnect_cached()\fRto connect to the same database with the same (initial) attributesit is a good idea to add a private attribute to the \fIconnect_cached()\fRcall to effectively limit the scope of the caching. For example:.PP.Vb 1\&  DBI\->connect_cached(..., { private_foo_cachekey => "Bar", ... });.Ve.PPHandles returned from that \fIconnect_cached()\fR call will only be returnedby other \fIconnect_cached()\fR call elsewhere in the code if those othercalls also pass in the same attribute values, including the private one.(I've used \f(CW\*(C`private_foo_cachekey\*(C'\fR here as an example, you can useany attribute name with a \f(CW\*(C`private_\*(C'\fR prefix.).PPTaking that one step further, you can limit a particular \fIconnect_cached()\fRcall to return handles unique to that one place in the code by setting theprivate attribute to a unique value for that place:.PP.Vb 1\&  DBI\->connect_cached(..., { private_foo_cachekey => _\|_FILE_\|_._\|_LINE_\|_, ... });.Ve.PPBy using a private attribute you still get connection caching forthe individual calls to \fIconnect_cached()\fR but, by making separatedatabase conections for separate parts of the code, the databasehandles are isolated from any attribute changes made to other handles..PPThe cache can be accessed (and cleared) via the \*(L"CachedKids\*(R" attribute:.PP.Vb 2\&  my $CachedKids_hashref = $dbh\->{Driver}\->{CachedKids};\&  %$CachedKids_hashref = () if $CachedKids_hashref;.Ve.PP\fI\f(CI\*(C`available_drivers\*(C'\fI\fR.IX Subsection "available_drivers".PP.Vb 2\&  @ary = DBI\->available_drivers;\&  @ary = DBI\->available_drivers($quiet);.Ve.PPReturns a list of all available drivers by searching for \f(CW\*(C`DBD::*\*(C'\fR modulesthrough the directories in \f(CW@INC\fR. By default, a warning is given ifsome drivers are hidden by others of the same name in earlierdirectories. Passing a true value for \f(CW$quiet\fR will inhibit the warning..PP\fI\f(CI\*(C`installed_drivers\*(C'\fI\fR.IX Subsection "installed_drivers".PP.Vb 1\&  %drivers = DBI\->installed_drivers();.Ve.PPReturns a list of driver name and driver handle pairs for all drivers\&'installed' (loaded) into the current process.  The driver name does notinclude the '\s-1DBD::\s0' prefix..PPTo get a list of all drivers available in your perl instalation you can use\&\*(L"available_drivers\*(R"..PPAdded in \s-1DBI\s0 1.49..PP\fI\f(CI\*(C`installed_versions\*(C'\fI\fR.IX Subsection "installed_versions".PP.Vb 3\&  DBI\->installed_versions;\&  @ary  = DBI\->installed_versions;\&  %hash = DBI\->installed_versions;.Ve.PPCalls \fIavailable_drivers()\fR and attempts to load each of them in turnusing \fIinstall_driver()\fR.  For each load that succeeds the drivername and version number are added to a hash. When running underDBI::PurePerl drivers which appear not be pure-perl are ignored..PPWhen called in array context the list of successfully loaded driversis returned (without the '\s-1DBD::\s0' prefix)..PPWhen called in scalar context a reference to the hash is returnedand the hash will also contain other entries for the \f(CW\*(C`DBI\*(C'\fR version,\&\f(CW\*(C`OS\*(C'\fR name, etc..PPWhen called in a void context the \fIinstalled_versions()\fR method willprint out a formatted list of the hash contents, one per line..PPDue to the potentially high memory cost and unknown risks of loadingin an unknown number of drivers that just happen to be installedon the system, this method is not recommended for general use.Use \fIavailable_drivers()\fR instead..PPThe \fIinstalled_versions()\fR method is primarily intended as a quickway to see from the command line what's installed. For example:.PP.Vb 1\&  perl \-MDBI \-e \*(AqDBI\->installed_versions\*(Aq.Ve.PPThe \fIinstalled_versions()\fR method was added in \s-1DBI\s0 1.38..PP\fI\f(CI\*(C`data_sources\*(C'\fI\fR.IX Subsection "data_sources".PP.Vb 2\&  @ary = DBI\->data_sources($driver);\&  @ary = DBI\->data_sources($driver, \e%attr);.Ve.PPReturns a list of data sources (databases) available via the nameddriver.  If \f(CW$driver\fR is empty or \f(CW\*(C`undef\*(C'\fR, then the value of the\&\f(CW\*(C`DBI_DRIVER\*(C'\fR environment variable is used..PPThe driver will be loaded if it hasn't been already. Note that if thedriver loading fails then \fIdata_sources()\fR \fIdies\fR with an error messagethat includes the string "\f(CW\*(C`install_driver\*(C'\fR" and the underlying problem..PPData sources are returned in a form suitable for passing to the\&\*(L"connect\*(R" method (that is, they will include the "\f(CW\*(C`dbi:$driver:\*(C'\fR" prefix)..PPNote that many drivers have no way of knowing what data sources mightbe available for it. These drivers return an empty or incomplete listor may require driver-specific attributes..PPThere is also a \fIdata_sources()\fR method defined for database handles..PP\fI\f(CI\*(C`trace\*(C'\fI\fR.IX Subsection "trace".PP.Vb 4\&  DBI\->trace($trace_setting)\&  DBI\->trace($trace_setting, $trace_filename)\&  DBI\->trace($trace_setting, $trace_filehandle)\&  $trace_setting = DBI\->trace;.Ve.PPThe \f(CW\*(C`DBI\->trace\*(C'\fR method sets the \fIglobal default\fR tracesettings and returns the \fIprevious\fR trace settings. It can alsobe used to change where the trace output is sent..PPThere's a similar method, \f(CW\*(C`$h\->trace\*(C'\fR, which sets the tracesettings for the specific handle it's called on..PPSee the \*(L"\s-1TRACING\s0\*(R" section for full details about the \s-1DBI\s0's powerfultracing facilities..Sh "\s-1DBI\s0 Utility Functions".IX Subsection "DBI Utility Functions"In addition to the \s-1DBI\s0 methods listed in the previous section,the \s-1DBI\s0 package also provides several utility functions..PPThese can be imported into your code by listing them inthe \f(CW\*(C`use\*(C'\fR statement. For example:.PP.Vb 1\&  use DBI qw(neat data_diff);.Ve.PPAlternatively, all these utility functions (except hash) can beimported using the \f(CW\*(C`:utils\*(C'\fR import tag. For example:.PP.Vb 1\&  use DBI qw(:utils);.Ve.PP\fI\f(CI\*(C`data_string_desc\*(C'\fI\fR.IX Subsection "data_string_desc".PP.Vb 1\&  $description = data_string_desc($string);.Ve.PPReturns an informal description of the string. For example:.PP.Vb 5\&  UTF8 off, ASCII, 42 characters 42 bytes\&  UTF8 off, non\-ASCII, 42 characters 42 bytes\&  UTF8 on, non\-ASCII, 4 characters 6 bytes\&  UTF8 on but INVALID encoding, non\-ASCII, 4 characters 6 bytes\&  UTF8 off, undef.Ve.PPThe initial \f(CW\*(C`UTF8\*(C'\fR on/off refers to Perl's internal SvUTF8 flag.If \f(CW$string\fR has the SvUTF8 flag set but the sequence of bytes itcontains are not a valid \s-1UTF\-8\s0 encoding then \fIdata_string_desc()\fRwill report \f(CW\*(C`UTF8 on but INVALID encoding\*(C'\fR..PPThe \f(CW\*(C`ASCII\*(C'\fR vs \f(CW\*(C`non\-ASCII\*(C'\fR portion shows \f(CW\*(C`ASCII\*(C'\fR if \fIall\fR thecharacters in the string are \s-1ASCII\s0 (have code points <= 127)..PPThe \fIdata_string_desc()\fR function was added in \s-1DBI\s0 1.46..PP\fI\f(CI\*(C`data_string_diff\*(C'\fI\fR.IX Subsection "data_string_diff".PP.Vb 1\&  $diff = data_string_diff($a, $b);.Ve.PPReturns an informal description of the first character differencebetween the strings. If both \f(CW$a\fR and \f(CW$b\fR contain the same sequenceof characters then \fIdata_string_diff()\fR returns an empty string.For example:.PP.Vb 6\& Params a & b     Result\& \-\-\-\-\-\-\-\-\-\-\-\-     \-\-\-\-\-\-\& \*(Aqaaa\*(Aq, \*(Aqaaa\*(Aq     \*(Aq\*(Aq\& \*(Aqaaa\*(Aq, \*(Aqabc\*(Aq     \*(AqStrings differ at index 2: a[2]=a, b[2]=b\*(Aq\& \*(Aqaaa\*(Aq, undef     \*(AqString b is undef, string a has 3 characters\*(Aq\& \*(Aqaaa\*(Aq, \*(Aqaa\*(Aq      \*(AqString b truncated after 2 characters\*(Aq.Ve.PPUnicode characters are reported in \f(CW\*(C`\ex{XXXX}\*(C'\fR format. Unicodecode points in the range U+0800 to U+08FF are unassigned and mostlikely to occur due to double-encoding. Characters in this rangeare reported as \f(CW\*(C`\ex{08XX}=\*(AqC\*(Aq\*(C'\fR where \f(CW\*(C`C\*(C'\fR is the correspondinglatin\-1 character..PPThe \fIdata_string_diff()\fR function only considers logical \fIcharacters\fRand not the underlying encoding. See \*(L"data_diff\*(R" for an alternative..PPThe \fIdata_string_diff()\fR function was added in \s-1DBI\s0 1.46..PP\fI\f(CI\*(C`data_diff\*(C'\fI\fR.IX Subsection "data_diff".PP.Vb 2\&  $diff = data_diff($a, $b);\&  $diff = data_diff($a, $b, $logical);.Ve.PPReturns an informal description of the difference between two strings.It calls \*(L"data_string_desc\*(R" and \*(L"data_string_diff\*(R"and returns the combined results as a multi-line string..PPFor example, \f(CW\*(C`data_diff("abc", "ab\ex{263a}")\*(C'\fR will return:.PP.Vb 3\&  a: UTF8 off, ASCII, 3 characters 3 bytes\&  b: UTF8 on, non\-ASCII, 3 characters 5 bytes\&  Strings differ at index 2: a[2]=c, b[2]=\ex{263A}.Ve.PPIf \f(CW$a\fR and \f(CW$b\fR are identical in both the characters they contain \fIand\fRtheir physical encoding then \fIdata_diff()\fR returns an empty string.If \f(CW$logical\fR is true then physical encoding differences are ignored(but are still reported if there is a difference in the characters)..PPThe \fIdata_diff()\fR function was added in \s-1DBI\s0 1.46..PP\fI\f(CI\*(C`neat\*(C'\fI\fR.IX Subsection "neat".PP.Vb 2\&  $str = neat($value);\&  $str = neat($value, $maxlen);.Ve.PPReturn a string containing a neat (and tidy) representation of thesupplied value..PPStrings will be quoted, although internal quotes will \fInot\fR be escaped.Values known to be numeric will be unquoted. Undefined (\s-1NULL\s0) valueswill be shown as \f(CW\*(C`undef\*(C'\fR (without quotes)..PPIf the string is flagged internally as utf8 then double quotes willbe used, otherwise single quotes are used and unprintable characterswill be replaced by dot (.)..PPFor result strings longer than \f(CW$maxlen\fR the result string will betruncated to \f(CW\*(C`$maxlen\-4\*(C'\fR and "\f(CW\*(C`...\*(Aq\*(C'\fR" will be appended.  If \f(CW$maxlen\fR is 0or \f(CW\*(C`undef\*(C'\fR, it defaults to \f(CW$DBI::neat_maxlen\fR which, in turn, defaults to 400..PPThis function is designed to format values for human consumption.It is used internally by the \s-1DBI\s0 for \*(L"trace\*(R" output. It shouldtypically \fInot\fR be used for formatting values for database use.(See also \*(L"quote\*(R".).PP\fI\f(CI\*(C`neat_list\*(C'\fI\fR.IX Subsection "neat_list".PP.Vb 1\&  $str = neat_list(\e@listref, $maxlen, $field_sep);.Ve.PPCalls \f(CW\*(C`neat\*(C'\fR on each element of the list and returns a stringcontaining the results joined with \f(CW$field_sep\fR. \f(CW$field_sep\fR defaultsto \f(CW", "\fR..PP\fI\f(CI\*(C`looks_like_number\*(C'\fI\fR.IX Subsection "looks_like_number".PP.Vb 1\&  @bool = looks_like_number(@array);.Ve.PPReturns true for each element that looks like a number.Returns false for each element that does not look like a number.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -