{
NotUsed = 0
int i
for (i = 0i <argci++)
{
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL")
}
printf("\n")
return 0
}
int main(int argc, char **argv)
{
sqlite3 *db
char *zErrMsg = 0
int rc
rc = sqlite3_open("test.db3", &db)
if (rc == SQLITE_OK)
{
rc = sqlite3_exec(db,
"CREATE TABLE test (id INTEGER NOT NULL, text VARCHAR(100))"
, callback, 0, &zErrMsg)
if (rc != SQLITE_OK) fprintf(stderr, "SQL error: %s\n", zErrMsg)
rc = sqlite3_exec(db,
"INSERT INTO test VALUES (1, 'text1')"
, callback, 0, &zErrMsg)
if (rc != SQLITE_OK) fprintf(stderr, "SQL error: %s\n", zErrMsg)
rc = sqlite3_exec(db,
"SELECT * FROM test"
, callback, 0, &zErrMsg)
if (rc != SQLITE_OK) fprintf(stderr, "SQL error: %s\n", zErrMsg)
sqlite3_close(db)
} else {
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db))
sqlite3_close(db)
return 1
}
return 0
}
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
NotUsed = 0
int i
for (i = 0i <argci++)
{
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL")
}
printf("\n")
return 0
}
int main(int argc, char **argv)
{
sqlite3 *db
char *zErrMsg = 0
int rc
rc = sqlite3_open("test.db3", &db)
if (rc == SQLITE_OK)
{
rc = sqlite3_exec(db,
"CREATE TABLE test (id INTEGER NOT NULL, text VARCHAR(100))"
, callback, 0, &zErrMsg)
if (rc != SQLITE_OK) fprintf(stderr, "SQL error: %s\n", zErrMsg)
rc = sqlite3_exec(db,
"INSERT INTO test VALUES (1, 'text1')"
, callback, 0, &zErrMsg)
if (rc != SQLITE_OK) fprintf(stderr, "SQL error: %s\n", zErrMsg)
rc = sqlite3_exec(db,
"SELECT * FROM test"
, callback, 0, &zErrMsg)
if (rc != SQLITE_OK) fprintf(stderr, "SQL error: %s\n", zErrMsg)
sqlite3_close(db)
} else {
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db))
sqlite3_close(db)
return 1
}
return 0
}
用Python建立最简单的web服务器
利用Python自带的包可以建立简单的web服务器。在DOS里cd到准备做服务器根目录的路径下,输入命令:
python -m Web服务器模块 [端口号,默认8000]
例如:
python -m SimpleHTTPServer 8080
然后就可以在浏览器中输入
http://localhost:端口号/路径
来访问服务器资源。
例如:
http://localhost:8080/index.htm(当然index.htm文件得自己创建)
其他机器也可以通过服务器的IP地址来访问。
这里的“Web服务器模块”有如下三种:
BaseHTTPServer: 提供基本的Web服务和处理器类,分别是HTTPServer和BaseHTTPRequestHandler。
SimpleHTTPServer: 包含执行GET和HEAD请求的SimpleHTTPRequestHandler类。
CGIHTTPServer: 包含处理POST请求和执行CGIHTTPRequestHandler类。
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)