<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
 <channel>
  <title>byte.crawl的实验田</title>
  <link>http://bitstream.blogbus.com</link>
  <description><![CDATA[我就要 1 mile wide, 1 inch deep
我还要 1 inch wide, 1 mile deep
]]></description>
  <generator> by blogbus.com </generator>
  <lastBuildDate>Thu, 01 Jan 1970 07:00:00 +0700</lastBuildDate>
  <image>
									<url>http://public.blogbus.com/profile/3/9/9/4679993/avatar_4679993_96.jpg</url>
									<title>byte.crawl的实验田</title>
									<link>http://bitstream.blogbus.com</link>
								</image>  <item>
   <title>使用gethostbyname由域名或主机名得IP地址(转载)</title>
   <description><![CDATA[<p><span style="font-size: medium;">使用这个东西，首先要包含2个头文件：<br />#include &lt;netdb.h&gt;<br />#include &lt;sys/socket.h&gt;</span></p>
<p><span style="font-size: medium;">struct hostent *gethostbyname(const char *name);<br />这个函数的传入值是域名或者主机名，例如"www.google.cn</span><span style="font-size: medium;">","wpc"等等。<br />传出值，是一个hostent的结构（如下）。如果函数调用失败，将返回NULL。</span></p>
<p><span style="font-size: medium;">struct hostent <br />{<br />&nbsp; char&nbsp; *h_name;<br />&nbsp; char&nbsp; **h_aliases;<br />&nbsp; int&nbsp;&nbsp; h_addrtype;<br />&nbsp; int&nbsp;&nbsp; h_length;<br />&nbsp; char&nbsp; **h_addr_list;<br />};<br />解释一下这个结构：<br />其中，<br />&nbsp; char *h_name 表示的是主机的规范名。例如</span>www.google.com<span style="font-size: medium;">的规范名其实是</span>www.l.google.com<span style="font-size: medium;">。<br />&nbsp; char&nbsp;&nbsp; **h_aliases 表示的是主机的别名.www.google.com</span><span style="font-size: medium;">就是google他自己的别名。有的时候，有的主机可能有好几个别名，这些，其实都是为了易于用户记忆而为自己的网站多取的名字。<br />&nbsp; int&nbsp;&nbsp; h_addrtype 表示的是主机ip地址的类型，到底是ipv4(AF_INET)，还是pv6(AF_INET6)<br />&nbsp; int&nbsp;&nbsp; h_length 表示的是主机ip地址的长度<br />&nbsp; int&nbsp;&nbsp; **h_addr_lisst 表示的是主机的ip地址，注意，这个是以网络字节序存储的。千万不要直接用printf带%s参数来打这个东西，会有问题的哇。所以到真正需要打印出这个IP的话，需要调用inet_ntop()。</span></p>
<p><span style="font-size: medium;">const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) ：<br />这个函数，是将类型为af的网络地址结构src，转换成主机序的字符串形式，存放在长度为cnt的字符串中。<br />这个函数，其实就是返回指向dst的一个指针。如果函数调用错误，返回值是NULL。</span></p>
<p>&nbsp;<br /><span style="font-size: medium;">下面是例程，有详细的注释。</span></p>
<p><span style="font-size: medium;">#include &lt;netdb.h&gt;<br />#include &lt;sys/socket.h&gt;</span></p>
<p><span style="font-size: medium;">int main(int argc, char **argv)<br />{<br />&nbsp;&nbsp;&nbsp; char *ptr,**pptr;<br />&nbsp;&nbsp;&nbsp; struct hostent *hptr;<br />&nbsp;&nbsp;&nbsp; char str[32];</span></p>
<p><span style="font-size: medium;">&nbsp;&nbsp;&nbsp; /* 取得命令后第一个参数，即要解析的域名或主机名 */<br />&nbsp;&nbsp;&nbsp; ptr = argv[1];</span></p>
<p><span style="font-size: medium;">&nbsp;&nbsp;&nbsp; /* 调用gethostbyname()。调用结果都存在hptr中 */<br />&nbsp;&nbsp;&nbsp; if((hptr = gethostbyname(ptr)) == NULL)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; printf("gethostbyname error for host:%s\n", ptr);<br />&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; return 0; /* 如果调用gethostbyname发生错误，返回1 */<br />&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="font-size: medium;">&nbsp;&nbsp;&nbsp; /* 将主机的规范名打出来 */<br />&nbsp;&nbsp;&nbsp; printf("official hostname:%s\n",hptr-&gt;h_name);</span></p>
<p><span style="font-size: medium;">&nbsp;&nbsp;&nbsp; /* 主机可能有多个别名，将所有别名分别打出来 */<br />&nbsp;&nbsp;&nbsp; for(pptr = hptr-&gt;h_aliases; *pptr != NULL; pptr++)<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("&nbsp; alias:%s\n",*pptr);</span></p>
<p><span style="font-size: medium;">&nbsp;&nbsp;&nbsp; /* 根据地址类型，将地址打出来 */<br />&nbsp;&nbsp;&nbsp; switch(hptr-&gt;h_addrtype)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; case AF_INET:<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; case AF_INET6:<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pptr=hptr-&gt;h_addr_list;</span></p>
<p><span style="font-size: medium;">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; /* 将刚才得到的所有地址都打出来。其中调用了inet_ntop()函数 */<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; for(;*pptr!=NULL;pptr++)<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("&nbsp; address:%s\n", inet_ntop(hptr-&gt;h_addrtype,&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *pptr, str, sizeof(str)));<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; break;<br />&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; default:<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("unknown address type\n");<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="font-size: medium;">&nbsp;&nbsp;&nbsp; return 0;<br />}<br /></span></p><!--sp--><br /><br /><div class="sysmsg"><b><a href="http://www.blogbus.com" target="_blank">博客大巴，你的个人传媒早班车</a></b></div><br /><br />]]></description>
   <link>http://bitstream.blogbus.com/logs/38907677.html</link>
   <author>byte.crawl</author>
   <pubDate>Mon, 04 May 2009 13:49:25 +0800</pubDate>
  </item>
  <item>
   <title>我不同意你说的话，但是我愿意誓死捍卫你说话的权利。</title>
   <description><![CDATA[<p>Ｆｒｏｍ　伏尔泰</p><!--sp--><br /><br /><div class="sysmsg"><b><a href="http://www.blogbus.com" target="_blank">博客大巴，你的个人传媒早班车</a></b></div><br /><br />]]></description>
   <link>http://bitstream.blogbus.com/logs/37968198.html</link>
   <author>byte.crawl</author>
   <pubDate>Thu, 16 Apr 2009 12:22:42 +0800</pubDate>
  </item>
  <item>
   <title>跨越文明之火，远离宁静与温暖，在纯粹的黑暗中燃起一点光亮。</title>
   <description><![CDATA[<p>嘘，安静～</p>
<p>我回来了</p><!--sp--><br /><br /><div class="sysmsg"><b><a href="http://www.blogbus.com" target="_blank">博客大巴，你的个人传媒早班车</a></b></div><br /><br />]]></description>
   <link>http://bitstream.blogbus.com/logs/37962427.html</link>
   <author>byte.crawl</author>
   <pubDate>Thu, 16 Apr 2009 11:01:25 +0800</pubDate>
  </item>
  <item>
   <title>关于DB2的锁</title>
   <description><![CDATA[<p><strong>锁级别分类</strong><br /><br />行级 <br />&nbsp;&nbsp;&nbsp; NS&nbsp;&nbsp;&nbsp; ?<br />&nbsp;&nbsp;&nbsp; NW&nbsp;&nbsp;&nbsp; ?<br />&nbsp;&nbsp;&nbsp; WE&nbsp;&nbsp;&nbsp; ?<br />表级<br />&nbsp;&nbsp;&nbsp; IN&nbsp;&nbsp;&nbsp; ?<br />&nbsp;&nbsp;&nbsp; IS<br />&nbsp;&nbsp;&nbsp; IX<br />&nbsp;&nbsp;&nbsp; SIX&nbsp;&nbsp;&nbsp; ?<br />&nbsp;&nbsp;&nbsp; Z&nbsp;&nbsp;&nbsp; ?<br /><br />行或表级<br />&nbsp;&nbsp;&nbsp; S<br />&nbsp;&nbsp;&nbsp; U<br />&nbsp;&nbsp;&nbsp; X<br /><strong><br />锁的获取</strong><br /><br />通过Index Scan<br />&nbsp;&nbsp;&nbsp; 有更新意图&nbsp;&nbsp;&nbsp; IX on table --&gt; S or X on rows<br />&nbsp;&nbsp;&nbsp; 无更新意图&nbsp;&nbsp;&nbsp; IS on table --&gt; S on rows<br />通过Table Scan<br />&nbsp;&nbsp;&nbsp; 有更新意图&nbsp;&nbsp;&nbsp; X on table<br />&nbsp;&nbsp;&nbsp; 无更新意图&nbsp;&nbsp;&nbsp; S on table</p><!--sp--><br /><br /><div class="sysmsg"><b><a href="http://www.blogbus.com" target="_blank">博客大巴，你的个人传媒早班车</a></b></div><br /><br />]]></description>
   <link>http://bitstream.blogbus.com/logs/35763219.html</link>
   <author>byte.crawl</author>
   <pubDate>Thu, 26 Feb 2009 16:28:05 +0800</pubDate>
  </item>
  <item>
   <title>DB2数据库索引概要</title>
   <description><![CDATA[<p>本质：</p>
<p>索引的本质应该就是map，更具体的讨论 <a href="http://www.maycode.com/index.php/forum.html?func=view&amp;id=1320&amp;catid=3" target="_blank">请看这里</a>。借此，可以加速检索的速度。</p>
<p>在数据库表中创建索引可能有两个目的：</p>
<ul>
<li>确保列值的唯一性</li>
<li>提高查询的性能</li>
</ul>
<p>索引的种类：</p>
<ul>
<li>唯一索引 （UNIQUE）&nbsp;&nbsp; 唯一索引用于保证唯一性，在创建主键时，会隐式地创建一个唯一索引</li>
<li>非唯一索引</li>
<li>降序/升序索引（DESC/AESC）&nbsp;&nbsp; 建立的索引都会按照一定顺序排序存储，可以显示地指定这个顺序。</li>
<li>双向索引 (ALLOW REVERSE SCAN ) 可以同时加速 MIN,MAX操作。</li>
<li>聚集索引 (CLUSTER)&nbsp; 建立聚集索引可以按照索引键顺序排序记录的物理存储（在以某种顺序检索数据时可提高性能）</li>
</ul>
<p>p.s. 另外在索引中可以存储额外的列值(不必须为索引列)，用以在检索数据时不必通过索引查询数据页，而直接取出结果。</p>
<p>&nbsp;</p>
<p>总结</p>
<p>索引在加快检索的同时，会带来副作用（更慢的更新、插入和删除）。所以，应该根据需要使用索引：</p>
<ul>
<li>对使用MAX操作的查询，用降序索引；MIN用升序索引；都有则用双向索引；</li>
<li>select * from table where id &gt; 100 and id &lt; 200 针对这种查询聚集索引可以提高性能;</li>
<li>select name from books where id &gt; 100 and id &lt; 200 如果大量检索，需要取出固定列的值，应使用包含列数据，避免访问数据页的开销</li>
</ul>
<p>另外，总结几点与SQL有关的注意事项：</p>
<ul>
<li>使用谓词like： like 'x%' 将会使用索引，而like '%x'将不能使用索引，而且因为谓词like的检索时间与字符串长度呈线性关系，使用VARCHAR代替CHAR可以去掉多余的空格，加快检索</li>
<li>使用 fetch first only 或 limit 限制结果集大小</li>
</ul>
<p>参考</p>
<h1><a href="http://news.csdn.net/n/20061207/98991.html" target="_blank"><span style="color: #0000ff;"><span style="font-size: 12px;">50种方法巧妙优化你的SQL Server数据库</span></span></a></h1><!--sp--><br /><br /><div class="sysmsg"><b><a href="http://www.blogbus.com" target="_blank">博客大巴，你的个人传媒早班车</a></b></div><br /><br />]]></description>
   <link>http://bitstream.blogbus.com/logs/35715251.html</link>
   <author>byte.crawl</author>
   <pubDate>Wed, 25 Feb 2009 17:30:46 +0800</pubDate>
  </item>
  <item>
   <title>[转]使用 GROUP BY 的规则</title>
   <description><![CDATA[<p>使用 GROUP BY 子句时，一定要记住下面的规则：
<br /> 1.&nbsp; 不能 GROUP BY text、image 或 bit 数据类型的列 
<br /> 2.&nbsp; SELECT 列表中指定的每一列也必须出现在 GROUP BY 子句中，除非这列是用于聚合函数。 
<br /> 3.&nbsp; 不能 GROUP BY 列的别名。 这是说 GROUP BY 字段列表中的所有字段必须是实际存在于 FROM 子句中指定的表中的列。 
<br /> 4.&nbsp; 进行分组前可以使用 WHERE 子句消除不满足条件的行。 
<br /> 5.&nbsp; 使用 GROUP BY 子句返回的组没有特定的顺序。可以使用 ORDER BY 子句指定想要的排序次序。 
</p><!--sp--><br /><br /><div class="sysmsg"><b><a href="http://www.blogbus.com" target="_blank">博客大巴，你的个人传媒早班车</a></b></div><br /><br />]]></description>
   <link>http://bitstream.blogbus.com/logs/35704320.html</link>
   <author>byte.crawl</author>
   <pubDate>Wed, 25 Feb 2009 13:57:16 +0800</pubDate>
  </item>
  <item>
   <title>[转]DB2 导入数据操作</title>
   <description><![CDATA[<p>例七：把C盘根目录下的org.txt文件中的数据导入到org表中 <br />import&nbsp;from&nbsp;c:\org.txt&nbsp;of&nbsp;del&nbsp;insert&nbsp;into&nbsp;org <br /><br />
导入命令和导出命令的格式基本上处于对应的关系，import对应export，from对应to，文件名和文件格式代表的含义相同，但是导入命令支持
ASC格式的文件，而导出命令不支持。另外，在导出命令的最后是一个SQL语句，用于选择要导出的数据，而导入命令最后不是SQL语句，而是插入数据的方
式以及目标表名称。 <br /><br />例八：从ASC格式文件中导入数据 <br />import&nbsp;from&nbsp;&nbsp;c:\org2.txt&nbsp;of&nbsp;asc&nbsp;method&nbsp;l(1&nbsp;5,6&nbsp;19,20&nbsp;25,26&nbsp;37,38&nbsp;50)&nbsp;insert&nbsp;into&nbsp;org <br />其中&nbsp;method&nbsp;l&nbsp;子句用于指定文本文件中每一个字段的起始位置和终止位置，每个起始位置和终止位置间用空格分开，字段之间用逗号分开。 <br />除了l方法之外，还有n方法和p方法，下面会叙述。 <br /><br />例九：利用n方法导入数据，并且创建新表。 <br />首先导出一个用例文件： <br />export&nbsp;to&nbsp;d:\org.ixf&nbsp;of&nbsp;ixf&nbsp;method&nbsp;n(a,b,c,d,e)&nbsp;select&nbsp;*&nbsp;from&nbsp;org <br />这样org.ixf文件中有五列数据，对应的列名分别为a、b、c、d、e <br />然后在从该文件中导入数据到一个新表中 <br />import&nbsp;from&nbsp;d:\org.ixf&nbsp;of&nbsp;ixf&nbsp;method&nbsp;n(d,e,b)&nbsp;replace_create&nbsp;into&nbsp;orgtest <br />该命令从文件中选取三列导入到表中，顺序可以不按照文件中原有的列的顺序。replace_create方式的叙述见下。 <br /><br />插入方式有： <br />INSERT&nbsp;方式&mdash;&mdash;在表中现有数据的基础之上追加新的数据。 <br />INSERT_UPDATE&nbsp;方式&mdash;&mdash;这种方式只能用于有主键的表，如果插入的数据与原有数据主键不冲突，则直接插入，如果主键冲突，则用新的数据代替原有数据。 <br />REPLACE&nbsp;方式&mdash;&mdash;先把表中现有的数据都删除，然后向空表中插入数据。 <br />REPLACE_CREATE&nbsp;方式&mdash;&mdash;表示如果表存在，则先把表中的数据都删除，然后向空表中插入数据；如果表不存在，则先根据文件中的字段创建表，然后再向表中插入数据。这种方式只能把IXF格式的文件中的数据插入到表中。 <br /><br />例十：利用p方法导入数据 <br />import&nbsp;from&nbsp;d:\org.ixf&nbsp;of&nbsp;ixf&nbsp;method&nbsp;p(4,5,2)&nbsp;replace&nbsp;into&nbsp;orgtest <br />该例子执行的效果和例九类似，只是把n方法换成了p方法，p方法后面的列表中指明列的序号即可，不需要指明列名。另外，此例中使用了replace方式插入数据，这会把表中现有的数据都删除，然后向空表中插入数据。 <br /><br />例十一：关于空值的导入 <br />对于ixf格式的文件，导入空值非常方便，因为里面已经记录了空值的信息。但是，对于ASC格式文件就有一定的难度了，因为DB2会直接插入空格，而不是空值。为此，DB2提供了一个子句进行控制：NULL&nbsp;INDICATORS <br /><br />import&nbsp;from&nbsp;&nbsp;c:\org2.txt&nbsp;of&nbsp;asc&nbsp;MODIFIED&nbsp;BY&nbsp;nullindchar=#&nbsp;method&nbsp;l(1&nbsp;5,6&nbsp;19,20&nbsp;25,26&nbsp;37,38&nbsp;50)&nbsp;NULL&nbsp;INDICATORS(0,0,0,0,38&nbsp;)&nbsp;replace&nbsp;into&nbsp;org
<br /><br />在这个例子中，NULL&nbsp;INDICATORS子句后面是一个列表，表示前面四个字段都不会存在空值，而第五个字段从38列开始，可能存在空值，而&nbsp;MODIFIED&nbsp;BY&nbsp;nullindchar=#&nbsp;子句表示在文件中第五个字段如果遇到&nbsp;#&nbsp;号，则表示为空值。 </p><!--sp--><br /><br /><div class="sysmsg"><b><a href="http://www.blogbus.com" target="_blank">博客大巴，你的个人传媒早班车</a></b></div><br /><br />]]></description>
   <link>http://bitstream.blogbus.com/logs/35603755.html</link>
   <author>byte.crawl</author>
   <pubDate>Mon, 23 Feb 2009 14:16:04 +0800</pubDate>
  </item>
  <item>
   <title>[书签]有那么多好工作 可惜我做不来 诶诶</title>
   <description><![CDATA[<p><a href="https://hr-info.web.cern.ch/hr-info/">https://hr-info.web.cern.ch/hr-info/</a></p><!--sp--><br /><br /><div class="sysmsg"><b><a href="http://www.blogbus.com" target="_blank">博客大巴，你的个人传媒早班车</a></b></div><br /><br />]]></description>
   <link>http://bitstream.blogbus.com/logs/34561430.html</link>
   <author>byte.crawl</author>
   <pubDate>Tue, 03 Feb 2009 11:02:05 +0800</pubDate>
  </item>
  <item>
   <title>SQL Server 2005 启动 报3417错误</title>
   <description><![CDATA[<p>&nbsp;</p>
<p>貌似是因为master.mdf出了什么状况，解决办法很简单，检查你的SQL 服务：</p>
<p>运行 services.msc , 找到 SQL Server 服务，点击登录选项卡，选择使用本地帐号，并勾选与本地服务交互。</p>
<p>问题解决</p><!--sp--><br /><br /><div class="sysmsg"><b><a href="http://www.blogbus.com" target="_blank">博客大巴，你的个人传媒早班车</a></b></div><br /><br />]]></description>
   <link>http://bitstream.blogbus.com/logs/34536711.html</link>
   <author>byte.crawl</author>
   <pubDate>Mon, 02 Feb 2009 17:26:38 +0800</pubDate>
  </item>
  <item>
   <title>【书签】一个数据库专家的文章</title>
   <description><![CDATA[<p><a class="example1" href="http://odetocode.com/Blogs/scott/archive/2008/01/31/11710.aspx" target="_blank"><span class="Apple-style-span" style="border-collapse: separate; color: #333333; font-family: 'Arial Narrow'; font-size: 14px; font-style: normal; font-variant: normal; font-weight: bold; letter-spacing: normal; line-height: 15px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">Versioning Databases &ndash; The Baseline</span></a></p>
<p>&nbsp;</p>
<p><span class="Apple-style-span" style="border-collapse: separate; color: #333333; font-family: 'Arial Narrow'; font-size: 14px; font-style: normal; font-variant: normal; font-weight: bold; letter-spacing: normal; line-height: 15px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">greenfield 的解释 见<a class="tablerow1" href="http://en.wikipedia.org/wiki/Greenfield_project" target="_blank">这里</a><br /></span></p><!--sp--><br /><br /><div class="sysmsg"><b><a href="http://www.blogbus.com" target="_blank">博客大巴，你的个人传媒早班车</a></b></div><br /><br />]]></description>
   <link>http://bitstream.blogbus.com/logs/34533724.html</link>
   <author>byte.crawl</author>
   <pubDate>Mon, 02 Feb 2009 16:09:48 +0800</pubDate>
  </item>
 </channel>
</rss>

