libcurl

libcurl是linux下curl的c lib库,小试一下它的流程

curl_global_init()初始化

curl_easy_init()返回curl句柄

curl_easy_setopt()设置相关参数及回调

curl_easy_perform()执行

 

 

int main(argc, **argv)

{

    curl_global_init(CURL_GLOBAL_ALL);
    curl = curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&arg);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, getdata);
    retcodes = curl_easy_perform(curl);

}

//userdata是CURLOPT_WRITEDATA中传过来的参数

size_t getdata( void *ptr, size_t size, size_t nmemb, void *userdata)

{

//进行一些处理,会进行多次调用

}

 

sphinxql得到结果数。

我想用sqhinxql只得到结果数。跟mysql里的count(*)一样。。。

直接这么干:

select count(*) from main_index;

会报语法错

查文档得:

Aggregate functions (AVG(), MIN(), MAX(), SUM()) in column list clause are supported. Arguments to aggregate functions can be either plain attributes or arbitrary expressions. COUNT(*) is implicitly supported as using GROUP BY will add @count column to result set. Explicit support might be added in the future. COUNT(DISTINCT attr) is supported. Currently there can be at most one COUNT(DISTINCT) per query and an argument needs to be an attribute. Both current restrictions on COUNT(DISTINCT) might be lifted in the future.

只有在group by的时候才能用count(*),好吧

select 1 as dummy,count(*) c from main_index group by dummy;

+——+——–+——-+——–+
| id | weight | dummy | @count |
+——+——–+——-+——–+
| 1001 | 1      | 1 | 15659 |
+——+——–+——-+——–+

得到了。。

还有一种方法

select * from main_index limit 0;

show meta;

+—————+——-+
| Variable_name | Value |
+—————+——-+
| total         |  67 |   
| total_found   |  67 |
| time | 0.001  | 
| keyword[0]     |  ha |
| docs[0] | 67  |
| hits[0] | 115 |
+—————+——-+

total_found这个也可以拿到。。