做项目时由于业务逻辑的需要,必须对数据表的一行或多行加入行锁,举个最简单的例子,图书借阅系统。假设 id=1 的这本书库存为 1 ,但是有 2 个人同时来借这本书,此处的逻辑为 :
Select restnum from book where id =1 ;
-- 如果 restnum 大于 0 ,执行 update
Update book set restnum=restnum-1 where id=1 ;
问题就来了,当 2 个人同时来借的时候,有可能第一个人执行 select 语句的时候,第二个人插了进来,在第一个人没来得及更新 book 表的时候,第二个人查到数据了,其实是脏数据,因为第一个人会把 restnum 值减 1 ,因此第二个人本来应该是查到 id=1 的书 restnum 为 0 了,因此不会执行 update ,而会告诉它 id=1 的书没有库存 了,可是数据库哪懂这些,数据库只负责执行一条条 SQL 语句,它才不管中间有没有其他 sql 语句插进来,它也不知道要把一个 session 的 sql 语句执行完再执行另一个 session 的。因此会导致并发的时候 restnum 最后的结果为 -1 ,显然这是不合理的,所以,才出现锁的概念, Mysql 使用 innodb 引擎可以通过索引 对数据行加锁。以上借书的语句变为:
......
When I try the command "gem install thrift" with Ruby 1.9.1, I got a compilation error with something related to a C function "strlcpy()".
Then I searched the web. It seems I am not alone and the community know it.
However I do not want to wait for official update, I want to try Cassandra and Thrift is a dependency I have to use now.
So, read on if you want a dirty fix.
Start command line console and run:
$ gem install thrift
If you got the error with "strlcpy", you should have thrift code downloaded in your ruby gems folder.
It is "C:\Ruby\lib\ruby\gems\1.9.1\gems\thrift-0.2.0" for my computer on Windows.
$ cd C:\Ruby\lib\ruby\gems\1.9.1\gems\thrift-0.2.0\ext
If you are using linux, check the lib/.../ext folder.
Open "extconf.rb" and "struct.c" with a text editor. Comment out HAVE_STRLCPY in "struct.c" like this:
/*
#ifndef HAVE_STRLCPY
  ......
To get it done is not easy. I spent a whole day to figure out the various compatibility issues along the way out.
Now there still might be potential issues, but it works by my rough test.
Step 1: Install Apache Cassandra
You may know that the Ruby gem cassandra will do it for you.
To me, I simply want to keep Cassandra independent from Ruby stuff, to ease the upgrade and administration.
Refer to my blog "Setup Cassandra on Windows"
(http://blog.csdn.net/goodxp/archive/2010/02/26/5327732.aspx) for details.
Step 2: Install Thrift (0.2.0)
If you do "gem install cassandra", it should install thrift automatically (being a dependency).
However, there is a compatibility issue on thrift with Ruby 1.9, so to fail Cassandra gem installation.
It will be better to install thrift first and fix it before installing cassandra gem.
Refer to my blog "fix thrift 0.2.0 installation with ruby 1.9.1"
&nb ......
学了一个学期的C语言,看了一个星期的ruby,我才发现为什么老师说C是最基础的,假如没有一个学期的C基础,那ruby我也不用看了。
Ruby和C语言有许多的相同点和不同点,在学习ruby时,有时可以用C里面的思维来理解,就像ruby里面的方法其实就跟C的函数如出一辙;ruby比C使用时随意的多,在C里声明变量还要求变量类型,而ruby却不用特意去声明类型,直接用就好;而对于输入,C也要分输入的类型,ruby却不用,直接用一个gets就可以,而且将读入的文本保存在预定义变量$_中,然后用chomp删除末尾的换行符,而C用的是gets接收换行符;对于多个单词的变量名,ruby的习惯是用下划分隔单词,而C去是习惯用大小写来区分不同的单词;ruby用do…end来界定块,而C用的是{},虽然ruby也可以用{},但{}只能包含单行代码块,而do…end包含多行代码块……等等。我发现的仅仅是皮毛,有什么错误希望大家指出来,跟多的还要等大家来探索,相互借鉴相互进步。
还有一个就是在安装rails时的问题,我老是装不好,最后在新建项目是发现里面提示还没装rails,然后我就点击安装就好了,不 ......
/*用CASE WHEN实现sqlserver数据库的分类汇总功能*/
/*例1:统计个数*/
/*表结构
id cityid major
1 1 A
2 1 B
3 2 B
4 2 A
5 1 A
6 2 B
7 1 C
8 2 C
结果:
cityId A B C
1 2 1 1
2 1 2 1
*/
SELECT cityId,SUM(CASE WHEN major='A' THEN 1 ELSE 0 END) AS 'A',
SUM(CASE W ......
Source Code
http://www.codefans.com/CodeList/Catalog_5_CodeTime_Desc_1.html
http://www.vscodes.com/sitemap.html
http://www.itlove.net/Soft/261/
DelphiX
http://www.micrel.cz/Dx/
http://www.delphi3d.net/index.php
http://www.pascalgamedevelopment.com/
http://www.2ccc.com/article.asp?articleid=2804
http://www.2ccc.com/article.asp?articleid=2387
http://www.2ccc.com/article.asp?articleid=2035
Delphi游戏开发网址大全!
2004-11-23 14:04:23 源码仓库-免费delphi源码下载 出处:大富翁
说明:用Delphi开发的CAD GIS软件!使用了OpenGL。免费的可视化Delphi 2D游戏开发引擎!)总计179个网站
毋庸置疑,Delphi是一个绝佳的、强大的游戏开发平台!希望这个网址列表能对Delphi程序员普及游戏开发知识作出一点贡献!
1、
http://www.savagesoftware.com.au/DelphiGamer/
说明:著名的Delphi游戏开发网站,分类详细,有资料,源码,Delphi开发的游戏网址等等!更新很快!
2、
http://turbo.gamedev.net/
说明:专业的Borland编译器游戏开发网站,站长水平很高,并且用Delphi开发了《疯狂保龄球》、《过山车大亨 ......