一直都想把web programming好好学习和实践一下,可惜总是持续了一段时间就停下了。最近由于xml keyword search research的一些idea用web的方式能够更好的呈现,因此又重新啃起了python。把lighttpd server配置好,随便写了一个小程序想试着运行一下,结果浏览器上出现了internal server error。对着程序检查了好久也没有发现什么问题。写程序用的是Notepad++,最后实在没辙只好打开IDLE,想用python shell run一下。打开一看就傻眼了,其中有一行代码因为偷懒是从另外一个地方copy过来的,所以indentation没有consistent,有一行代码用了4个空格,其他的用的是tab,在Notepad++中也没有看出来,就没有朝indentation去想。编程有时真是一个silly mistake就可以浪费很长的时间。
前一阵在做一个关于xml的research project的prototype,在这个项目中需要用fopen为每一个tag建立一个同名文件来保存相关的position information。结果发现在创建一个名为aux的文件时返回NULL指针,后来查阅资料原来con,aux,prn是系统保留关键字,是DOS的系统device句柄,con是标准输入输出,aux是com1,prn是printer接口。因此在创建以这三个关键字命名的文件时都会返回NULL指针,而且在创建以con.,aux.,prn. 为前缀的文件时也会返回空指针,例如创建aux.a文件,prn.xn文件等等。
Berkeley DB engine supports duplicate records that share a key. The
duplicate records can be sorted or unsorted, which depends on the flag
is DB_DUP or DB_DUPSORT. If DB_DUPSORT value is selected, we should
provide a sorting function. The engine does not accept two duplicate
records is judged to be equal to each other by the sorting function. In
other words, if two duplicate records are equal to each other, only one
copy will be stored. However, this can't be accepted in some scenarios.
One solution for this problem is to adjust the return value of sorting function. For example,
int CompareRecord(Db *dbp, const Dbt *a, const Dbt *b)
{
int ai, bi
int ret = 0;
memcpy(&ai, a->get_data(), sizeof(int));
memcpy(&bi, b->get_data(), sizeof(int));
ret = ai - bi;
if(ret == 0)
ret = -1;
return ret;
}
In
the codes above, if ai is equal to bi, the sorting function will return
-1 instead of 0. Therefore, both ai and bi can be stored in the
database.
Recent Comments