fletcher's mindview

Thursday, June 08, 2006

Take time to Think,Enjoy,Appreciate and Love.

FROM:http://www.dc9.cn/post/108.html

GRE的课接近尾声了,今天张雷东给我们上了最后一节的Argument&Math.临结束时留给我们一句很有意义的话:Take time to TEAL.意思是Take time to Think,Enjoy,Appreciate and Love.
Think
就是让我们多静下心来冷静思考,不要随大流,不要说别人说出过你就出国,别人说找工作你就找工作,别人考研你就考研,要冷静想一想对我有没有用?我究竟需要什么?我能得到什么?我为什么要选择?有什么动力?今后应该怎么面对即将发生的事情?这些都是我经常思考的,所以他说完Think我很有感触。
Enjoy
意思是要享受生活。他说到这里,我突然想到一句话,意思是在艰苦奔向人生目标的时候,要享受路边美丽的风景,不要错过人生应该拥有的美好。也许我们现在会觉得学习很苦很累,但是要苦中作乐,意识到生活的美好,生命的美好与珍贵。
Appreciate
意思是让我们学会感激赞赏别人。这样会让我们在生活中更易得到社会的认可。
Love
用心爱身边的每一个人。生活是充满爱的,生活是美好的。我想,这就是这个老师的人生观吧...

Tuesday, May 23, 2006

理想高七成人工作没激情

发信人: runhua (回想), 信区: WorkLife
标 题: [zz]理想高七成人工作没激情
发信站: 水木社区 (Wed May 24 09:41:52 2006), 站内

理想高七成人工作没激情
来源:北京科技报(06/05/24 07:39)
  总觉得工作没意思,没激情,对工作不感兴趣,觉得实现不了理想……这占到职场“不和谐”的首位。专家认为,这种状态,是因为很多人无法处理好理想与职业间的关系,导致心态越来越麻木。  
焦点话题
  ★近七成上班族“不和谐”地工作着,只有不到10%的被调查者比较和谐
  ★近40%的被调查者的工作并不和谐
  ★超过40%的被调查者在工作中与他人的关系并不和谐
  ★超过50%的被调查者与所在单位的关系并不和谐
  ★近40%的被调查者的职场体验并不和谐
  这组令人感到震惊的数字,出自中国人民大学公共管理学院组织与人力资源研究所与新浪新闻频道联合实施的“2006年中国上班族工作和谐指数调查”,共有近4000名在职人员通过网络接受了调查。
  在众多“不和谐”因素中,排在前三位的分别是“自己的工作没有什么意思”(63.4%)、“自己没有得到合理回报”(49.2%)和“工作安全感比较低”(46.7%)。
  工作几年,我们成了“木乃伊”
  赵先生从成都电子科技大学毕业已经七年了,当初放弃了继续保研读书的机会,选择到北京工作,在西门子已经做到了高级主管的位置。别人都非常羡慕,可他内心深处一直把大学教师作为他的理想。最近大学同学聚会,同学小李读完博士后回老家当大学老师,生活比较舒适和轻松。相比而言,赵先生觉得自己生活压力太大了,刚刚才奋斗出一套北京房子,每天都拖着一身疲惫回家,越来越觉得自己追求的职业理想已遥不可及,困惑无奈一直困扰着他……
  瑞贝卡在一家私立双语学校做老师,毕业时她在媒体工作,她觉得压力太大,转而做了老师。现在这所私立小学待遇很不错,压力也比较小,可是生活非常平淡,她总是觉得工作很无趣,慢慢地,她也对自己的职业生涯产生怀疑,一味追求平淡的工作,是不是意味着放弃理想和志向?其实我们都产生过同样的疑问,几年工作后,进入职场时的理想被现实生活逐渐磨平,每天在惯性中机械地前进,变成了一具具“木乃伊”。
  年轻人不要把麻木当成了适应
  为什么越来越多人的热情在逐渐消磨,觉得理想和现实作不和谐?北京市智慧之光咨询有限公司总经理、职业指导专家张琼文先生解释道:“首先在于我们职业理想的不和谐,学生充满了理想主义,个人对自己的要求过高,往往难以实现预定的高要求;其次是成长结果不和谐,青年人容易‘志向远大,才疏学浅’,犯眼高手低的毛病,有些人总拿自己认为正确的观点来修正别人,不可预计的后果可能是巨大的;第三,职场路径不和谐,我们常常犯了这样的错误,不去修正行动路线和思维模式,而是在不停修正奋斗的目标,刚出校门雄心壮志,意气风发,到了三十岁,生活的压力使自己不断改变最初的梦想,目标一点一点缩小,然后埋葬在现实生活中。”张琼文提醒,时间一长,一些年轻人会把麻木当成了适应,以为这种状况只是时间磨平了自己的棱角,变得“成熟”而已。其实,职场中,适应是一种积极心态,麻木是一种消极心态。这是完全不能混淆的。
  成长“倒挂”对未来职场人有潜在危害张琼文忧虑地告诉记者:“初涉职场的人往往理想太大,源头在于现在的年轻人在正规教育中处于‘倒挂’状态。‘倒挂’就是颠倒了教育的顺序,小学生我们教导‘五讲四美三热爱’,中学生我们教育‘热爱班集体’,到了大学老师最多的就是说‘找到一份好工作’了。”“他们在被动成长的惯性中沉默了太久,远远不能应付现实职场中遇到的问题。多数人还没有认识到‘透析’自己的重要性,因此就少了职业的定位,不知道做自己该做的事。”“这个世界没有懒人,干自己不喜欢干的工作才会偷懒,自己对工作没有了热情,自然也没有了工作的感觉,‘和谐’又从何而谈?中国有句老话‘善始善终’讲的其实也就是这个道理。”青年人必须清楚每个阶段我们必须做每个阶段该做的事。用自己最富有激情的时间和精力创造最丰富的价值,不是摸索着适应这个社会,时间久了,创造力和激情自然就消失了。
  “修身”“齐家”“治国”继而———“平天下”“要分清职业理想和理想职业不是一回事。”北京东明成功国际咨询中心咨询师赵劭祎告诫更为直接:“一般认为,只要你的职业理想符合社会需要,而自己又确实具备从事那种职业的素质,并且愿意不断地付出努力,会有一天实现自己的职业理想;而理想职业却带有很大的幻想成分,职业理想偏重理想,理想职业侧重职业,终究是两种不同的认识。当个人的能力、职业理想与社会最佳结合时,即达到三者的有机统一时,这个职业才是你的理想职业。”职场人士面对职业理想和现实的落差时,应该怎样调和心态,让自己能实现职业理想,也能找到理想职业呢?张琼文给出了一道古方:“修身”、“齐家”、“治国”。

--※ 来源:·水木社区 http://newsmth.net·[FROM: 219.142.114.*]

加大MySql的最大连接数

加大MySql的最大连接数
日期:2005-10-23 点击:278 作者: 来源:
MAX QUERIES PER HOUR --- 每小时的最大查询次数
MAX UPDATES PER HOUR --- 每小时的最大更新次数
MAX CONNECTIONS PER HOUR --- 每小时最多连接次数
在Win下可以修改my.ini:4.0及一下版本在[mysqld]所属下插入
set-variable=max_connections=1000(或更多) 即可。4.1以上修改max_connections的属性max_connections=1000(或更多) 即可。
在Unix/Linux下:mysql的最大连接数默认是100, 这个数值对于并发连接很多的数据库应用是远远不够的,可以把它适当调大whereis safe_mysqld 找到safe_mysqld的位置,然后编辑它,
找到mysqld启动的那两行,在后面加上参数 -O max_connections=1000
例如
--- safe_mysqld.orig Mon Sep 25 09:34:01 2000
+++ safe_mysqld Sun Sep 24 16:56:46 2000
@@ -109,10 +109,10 @@
if test "$#" -eq 0
then
nohup $ledir/mysqld --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR
- --skip-locking >> $err_log 2>&1
+ --skip-locking -O max_connections=1000 >> $err_log 2>&1
else
nohup $ledir/mysqld --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR
- --skip-locking "$@" >> $err_log 2>&1
+ --skip-locking "$@" -O max_connections=1000 >> $err_log 2>&1
fi
if test ! -f $pid_file # This is removed if normal shutdown
then
然后关闭mysql重启它,用 /mysqladmin所在路径/mysqladmin -uroot -p variables 输入root数据库账号的密码后可看到 max_connections 1000 即新改动已经生效。

注:在mysql 4.07版本中,在safe_mysqld文件的第274和276行

Monday, May 22, 2006

blogger of MS 关心  

记录一下,随时访问:
http://blog.joycode.com/xinz/

Thursday, May 18, 2006

思念

今天还是会想起她,工作一点进展都没有,就是一直对着电脑发呆。想给她打电话,但是不知道该说些什么!虽然明明知道不适合自己,但是自己心里还是有那么一点期许存在!为什么呢?是内心深处的阴暗作祟吗?

Wednesday, May 17, 2006

她走了!

Jenny 走了,以为跟我一起到公司来的同事,她说她又要去英国了!
今天就不过来上班了,不知道为什么自己内心有一丝丝的痛,自己
从4月16日一起过来报到上班,开始认识。5月17日就离开了,而且她中间还有一周的时间在请假,就是这么几天的认识时间

Monday, May 15, 2006

How I Work: Lonn Johnston, President,Page One PR

一个网站上的调查性资料,讲述了自己是如何工作的,可能会对自己有借鉴意义.

摘自:http://weblog.infoworld.com/openresource/archives/2006/05/how_i_work_lonn.html

How I Work: Lonn Johnston, President, Page One PR
Filed under: Random
What is your role?
I'm the founder of Page One PR, a PR agency in Palo Alto that works with some of the coolest open source companies. We're about 4 years old. I first got involved with open source in 1998 when I helped launch TurboLinux in North America. My Page One PR partner, Craig Oda, was the original founder of the Tokyo Linux Users' Group back in 1993. He and I worked together on the executive team at TurboLinux (and burned through $95M in venture money). I think we made every mistake possible around open source business at TurboLinux and we try to help our clients avoid the mistakes that we made. We also made a lot of friends along the way with reporters, analysts and vendors. In open source, it's good to know a lot of people and have a decent reputation.
What is your computer setup?
It's amazing to me how many folks responding to this survey run Mac notebooks for their work computer. I switched my shop to Macs half a year ago to escape the Windows plague of viruses and spyware. Many of our people work in distributed offices. We lost 4 hard drives to Windows pests in three months. It was just awful. Call Dell or IBM under the warranty and they'll fix it, but both claim spyware and viruses are by far the leading cause of drive failures in notebooks. I still find Linux on the desktop not worth the hassles (please don't flame me; I tried for 2 years).
What desktop software applications do you use daily?
Apple mail, iCal, Microsoft Office, Skype, iTunes, FileMaker Pro, Firefox for browsing, and Adium (IM for lots of different clients, inlcuding Yahoo, AIM, etc...).?
What websites do you visit every day?
All the news sites plus Slashdot. I haven't figured out RSS yet.
Don't forget dead trees. I read four dailies every morning: The New York Times, the Wall Street Journal, the San Jose Mercury News and the San Francisco Chronicle. I was a reporter for years at the LA Times and taught journalism at UC Berkeley. I still love the daily printed word. I know there are only about 11 of us left in high tech, however.
What mobile device or cell phone do you use?
Treo 650. It's much more reliable than the old 600s. You still can't read the screen in daylight, though.?
Do you use IM?I love it. And I was a very late adopter. It's the best way to ask quick questions, work with clients during a call, check if someone's available for a call, etc...
Do you use a VoIP phone?
I like Skype a lot but most of our clients who have installed company-wide VoIP phone systems have had a ton of trouble. It's not there yet, IMHO.
Do you have a personal organization theory?
I'm a flat guy. Our agency has no titles. Everyone does everything. It's like a start-up. I write press releases, build editorial calendars and do all kinds of tasks that? are typically delegated down. But I find these tasks a great way to stay close to the game, close to reporters, and close to clients. Make time to think and run your business, but keep your hands in the day-to-day operations, too.
Anything else?
Free PR advice. Don't just call reporters when you need them. Build relationships, have something to say, be genuine, don't be boring, never tell a lie, and don't be afraid to gossip.

跟着去FB

上周五跟公司的同事去徐家汇一条很偏僻的巷子里吃了一条(哦,不,是半条)很奇怪的鱼,粉红色的肉,看起来怪怪的,并且号称是新疆一个湖里特有的;喝了一种很奇怪的果汁,好象叫nano,味道很奇怪,据说也是很大补的.
还好吃饭之前流了很多的鼻血,趁机补一下!但是后来几天还是止不住,看来是不流痛快不罢休!

Friday, May 12, 2006

call mysql strored procedure in c souce code(使用c api调用mysql stored procedure)

如何使用mysql 提供的c api来调用sp呢?这是这几天一直研究的问题,其实本周以来一直研究的就是mysql的sp问题,还好通过今天的加班最终终于把它给搞定了.
5.1放假回来,周一开始网上搜集资料,准备写一个树型查询的sp,由于休假时间可能稍微长了一点,成效不大,昏昏沉沉的过去了;同样第二天也这样过去了.
 呵呵,周三开始正式的写sp,幸好找到了一个示例,修修改改的就开始测试了,中间遇到了很多问题,google了半天终于把问题一个一个给解决了,其中就设置recursion的深度值这个问题就耗费了我很长很长的时间;不过最后终于还是完成了.下面就是自己写的针对Agent table执行树型查询的sp:

支持从上向下进行树型查询的sp代码:(当然稍微修改一下就可以实现从下向上的树型查询功能)
==========================================================
CREATE PROCEDURE agent_tree(start_with VARCHAR(16))
proc:
BEGINDECLARE temporary_table_exists BOOLEAN;
BEGINDECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END;
DROP TABLE IF EXISTS Temporary_Table;
END;
BEGINDECLARE v_account_number VARCHAR(16);
DECLARE v_name VARCHAR(24);
DECLARE v_parent_id VARCHAR(16);
DECLARE done, error BOOLEAN DEFAULT FALSE;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTIONSET error = TRUE;
CREATE TEMPORARY TABLE Temporary_Table(Account_number VARCHAR(16),Name VARCHAR(24), Parent_id VARCHAR(16));
IF error THENSELECT 'CREATE TEMPORARY failed';
LEAVE proc;
END IF;
SET temporary_table_exists=TRUE;
SELECT Account_number, Name, Parent_idINTO v_account_number, v_name, v_parent_id FROM AgentWHERE Account_number = start_with limit 1;
IF error THENSELECT 'First SELECT failed';
LEAVE proc;
END IF;
IF v_account_number IS NOT NULL THENINSERT INTO Temporary_Table VALUES(v_account_number, v_name, v_parent_id);
IF error THENSELECT 'First INSERT failed';
LEAVE proc;
END IF;
CALL agent_tree2(v_account_number);
IF error THENSELECT 'First CALL agent_tree2() failed';
END IF;
END IF;
SELECT Account_number, Name, Parent_idFROM Temporary_Table;
IF error THENSELECT 'Temporary SELECT failed';
LEAVE proc;
END IF;
END;
IF temporary_table_exists THENDROP TEMPORARY TABLE Temporary_Table;
END IF;
END;

CREATE PROCEDURE agent_tree2 (start_with VARCHAR(16))
proc:BEGIN
DECLARE v_account_number VARCHAR(16);
DECLARE v_name VARCHAR(24);
DECLARE v_parent_id VARCHAR(16);
DECLARE done, error BOOLEAN DEFAULT FALSE;
DECLARE c CURSOR FORSELECT Account_number, Name, Parent_idFROM Agent WHERE Parent_id = start_with;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTIONSET error = TRUE;
OPEN c;
IF error THENSELECT 'OPEN failed';
LEAVE proc;
END IF;
REPEATSET v_account_number=NULL;
FETCH c INTO v_account_number, v_name, v_parent_id;
IF error THENSELECT 'FETCH failed';
LEAVE proc;
END IF;
IF done=FALSE THENINSERT INTO Temporary_Table VALUES(v_account_number, v_name, v_parent_id);
IF error THENSELECT 'INSERT in agent_tree2() failed';
END IF;
CALL agent_tree2(v_account_number);
IF error THENSELECT 'Recursive CALL agent_tree2() failed';
END IF;
END IF;
UNTIL done = TRUEEND REPEAT;
CLOSE c;
IF error THENSELECT 'CLOSE failed';
END IF;
END;
===============================================
下面看结果吧:
mysql> select * from Agent;
+-----------+----------------+--------+-----------+--------+--------------+
Unique_id Account_number Name Parent_id Active Phone_number
+-----------+----------------+--------+-----------+--------+--------------+
1 111111 host 000000 y 10000
2 111112 Agent1 111111 y 10001
3 111113 Agent2 111111 y 10002
4 111114 Agent3 111111 y 10003
5 111115 Agent4 111112 y 10004
6 111116 Agent5 111113 y 10005
7 111117 Agent6 111115 y 10006
+-----------+----------------+--------+-----------+--------+--------------+
7 rows in set (0.00 sec)
mysql> call agent_tree('111111');
+----------------+--------+-----------+
Account_number Name Parent_id
+----------------+--------+-----------+
111111 host 000000
111112 Agent1 111111
111115 Agent4 111112
111117 Agent6 111115
111113 Agent2 111111
111116 Agent5 111113
111114 Agent3 111111
+----------------+--------+-----------+
7 rows in set (0.88 sec)
Query OK, 0 rows affected, 1 warning (0.90 sec)
mysql>

在完成了该部分功能之后,就需要写一段C代码来call 这个sp程序,所以又开始研究这个问题.
刚开始准备实现这个功能的时候,自己是一头的雾水,完全不知道从哪里下手?在google 很久没有找到答案(而且刚开始也不知道问什么东西,可能已经找到答案,却被忽视了),所以开始在CU上发帖子咨询,等了几天没有人回答,这时候突然来到了mysql 的论坛,找到C/C++版开始读帖子,慢慢的发现了解决办法.(所以解决问题还是要找对地方,世界上不可能就我一个人在做这个东西的).好了,下边直接贴代码吧:

#include
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char* argv[])
{
MYSQL handle;
mysql_init(&handle);
if(&handle == NULL){
printf("mysql_init error\n");
return -1;
}
if(!mysql_real_connect(&handle, "localhost", "root", NULL, "Geopacket", 0, NULL,CLIENT_MULTI_STATEMENTS CLIENT_MULTI_RESULTS)){
printf("mysql_real_connect error\n");
mysql_close(&handle);
return -1;
}
const char* sqlQuery = "SET @@max_sp_recursion_depth=3; SET @msg = '111111'; CALL agent_tree(@msg);";
if(mysql_real_query(&handle, sqlQuery, (unsigned long) strlen(sqlQuery))){
printf("mysql_real_query error\n");
mysql_close(&handle);
return -1;
}
printf("mysql_real_query: %s\n", sqlQuery);
MYSQL_RES* result=NULL;
do{
printf("=================================\n");
/* store the resultset */
result = mysql_store_result(&handle);
if(NULL == result){ /* if the resultset was null, 'continue' and get next resultset. */
printf("Empty resultset retrieved\n");
continue;
}
/* retrieve the first row */
MYSQL_ROW row = NULL;
while(row = mysql_fetch_row(result)) {
MYSQL_FIELD *mysqlFields = mysql_fetch_fields(result);
const char* field_name = mysqlFields[0].name;
/* get the length of the data of the first row in the 1st column of the resultset. */
unsigned long* field_lengths = mysql_fetch_lengths(result);
unsigned long field_length = field_lengths[0];
/* copy the data to a null terminated string buffer. */
char* fieldData = (char *)malloc(field_length + 1);
memset(fieldData, '\0', field_length + 1);
memcpy(fieldData, row[0], field_length);
/* output the results. */
printf("%s: %s.\n", field_name, fieldData);
/* perform memory cleanup. */
free(fieldData);
}
mysql_free_result(result);
}while(mysql_next_result(&handle) == 0);
/* free the resultset. */
mysql_free_result(result);
mysql_close(&handle);
return 0;
}

同样,下边是代码执行结果:
#gcc -I/usr/include/mysql 1.c -L/usr/lib/mysql -lmysqlclient -lpthread -lz -o 1.out
# ./1.out
goodmysql_real_query: SET @@max_sp_recursion_depth=3; SET @msg = '111111'; CALL agent_tree(@msg);
=================================
Empty resultset retrieved
=================================
Empty resultset retrieved
=================================
Account_number: 111111.
Account_number: 111112.
Account_number: 111115.
Account_number: 111117.
Account_number: 111113.
Account_number: 111116.
Account_number: 111114.
=================================
Empty resultset retrieved
#

其中在编写该段代码遇到的一些问题,在另外一个帖子中贴出来吧.


call mysql strored procedure in c souce code(使用c api调用mysql stored procedure)

如何使用mysql 提供的c api来调用sp呢?这是这几天一直研究的问题,其实本周以来一直研究的就是mysql的sp问题,还好通过今天的加班最终终于把它给搞定了.
5.1放假回来,周一开始网上搜集资料,准备写一个树型查询的sp,由于休假时间可能稍微长了一点,成效不大,昏昏沉沉的过去了;同样第二天也这样过去了.
 呵呵,周三开始正式的写sp,幸好找到了一个示例,修修改改的就开始测试了,中间遇到了很多问题,google了半天终于把问题一个一个给解决了,其中就设置recursion的深度值这个问题就耗费了我很长很长的时间;不过最后终于还是完成了.下面就是自己写的针对Agent table执行树型查询的sp:

支持从上向下进行树型查询的sp代码:(当然稍微修改一下就可以实现从下向上的树型查询功能)
==========================================================
CREATE PROCEDURE agent_tree(start_with VARCHAR(16))
proc:
BEGINDECLARE temporary_table_exists BOOLEAN;
BEGINDECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END;
DROP TABLE IF EXISTS Temporary_Table;
END;
BEGINDECLARE v_account_number VARCHAR(16);
DECLARE v_name VARCHAR(24);
DECLARE v_parent_id VARCHAR(16);
DECLARE done, error BOOLEAN DEFAULT FALSE;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTIONSET error = TRUE;
CREATE TEMPORARY TABLE Temporary_Table(Account_number VARCHAR(16),Name VARCHAR(24), Parent_id VARCHAR(16));
IF error THENSELECT 'CREATE TEMPORARY failed';
LEAVE proc;
END IF;
SET temporary_table_exists=TRUE;
SELECT Account_number, Name, Parent_idINTO v_account_number, v_name, v_parent_id FROM AgentWHERE Account_number = start_with limit 1;
IF error THENSELECT 'First SELECT failed';
LEAVE proc;
END IF;
IF v_account_number IS NOT NULL THENINSERT INTO Temporary_Table VALUES(v_account_number, v_name, v_parent_id);
IF error THENSELECT 'First INSERT failed';
LEAVE proc;
END IF;
CALL agent_tree2(v_account_number);
IF error THENSELECT 'First CALL agent_tree2() failed';
END IF;
END IF;
SELECT Account_number, Name, Parent_idFROM Temporary_Table;
IF error THENSELECT 'Temporary SELECT failed';
LEAVE proc;
END IF;
END;
IF temporary_table_exists THENDROP TEMPORARY TABLE Temporary_Table;
END IF;
END;

CREATE PROCEDURE agent_tree2 (start_with VARCHAR(16))
proc:BEGIN
DECLARE v_account_number VARCHAR(16);
DECLARE v_name VARCHAR(24);
DECLARE v_parent_id VARCHAR(16);
DECLARE done, error BOOLEAN DEFAULT FALSE;
DECLARE c CURSOR FORSELECT Account_number, Name, Parent_idFROM Agent WHERE Parent_id = start_with;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTIONSET error = TRUE;
OPEN c;
IF error THENSELECT 'OPEN failed';
LEAVE proc;
END IF;
REPEATSET v_account_number=NULL;
FETCH c INTO v_account_number, v_name, v_parent_id;
IF error THENSELECT 'FETCH failed';
LEAVE proc;
END IF;
IF done=FALSE THENINSERT INTO Temporary_Table VALUES(v_account_number, v_name, v_parent_id);
IF error THENSELECT 'INSERT in agent_tree2() failed';
END IF;
CALL agent_tree2(v_account_number);
IF error THENSELECT 'Recursive CALL agent_tree2() failed';
END IF;
END IF;
UNTIL done = TRUEEND REPEAT;
CLOSE c;
IF error THENSELECT 'CLOSE failed';
END IF;
END;
===============================================
下面看结果吧:
mysql> select * from Agent;
+-----------+----------------+--------+-----------+--------+--------------+
Unique_id Account_number Name Parent_id Active Phone_number
+-----------+----------------+--------+-----------+--------+--------------+
1 111111 host 000000 y 10000
2 111112 Agent1 111111 y 10001
3 111113 Agent2 111111 y 10002
4 111114 Agent3 111111 y 10003
5 111115 Agent4 111112 y 10004
6 111116 Agent5 111113 y 10005
7 111117 Agent6 111115 y 10006
+-----------+----------------+--------+-----------+--------+--------------+
7 rows in set (0.00 sec)
mysql> call agent_tree('111111');
+----------------+--------+-----------+
Account_number Name Parent_id
+----------------+--------+-----------+
111111 host 000000
111112 Agent1 111111
111115 Agent4 111112
111117 Agent6 111115
111113 Agent2 111111
111116 Agent5 111113
111114 Agent3 111111
+----------------+--------+-----------+
7 rows in set (0.88 sec)
Query OK, 0 rows affected, 1 warning (0.90 sec)
mysql>

在完成了该部分功能之后,就需要写一段C代码来call 这个sp程序,所以又开始研究这个问题.
刚开始准备实现这个功能的时候,自己是一头的雾水,完全不知道从哪里下手?在google 很久没有找到答案(而且刚开始也不知道问什么东西,可能已经找到答案,却被忽视了),所以开始在CU上发帖子咨询,等了几天没有人回答,这时候突然来到了mysql 的论坛,找到C/C++版开始读帖子,慢慢的发现了解决办法.(所以解决问题还是要找对地方,世界上不可能就我一个人在做这个东西的).好了,下边直接贴代码吧:

#include
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char* argv[])
{
MYSQL handle;
mysql_init(&handle);
if(&handle == NULL){
printf("mysql_init error\n");
return -1;
}
if(!mysql_real_connect(&handle, "localhost", "root", NULL, "Geopacket", 0, NULL,CLIENT_MULTI_STATEMENTS CLIENT_MULTI_RESULTS)){
printf("mysql_real_connect error\n");
mysql_close(&handle);
return -1;
}
const char* sqlQuery = "SET @@max_sp_recursion_depth=3; SET @msg = '111111'; CALL agent_tree(@msg);";
if(mysql_real_query(&handle, sqlQuery, (unsigned long) strlen(sqlQuery))){
printf("mysql_real_query error\n");
mysql_close(&handle);
return -1;
}
printf("mysql_real_query: %s\n", sqlQuery);
MYSQL_RES* result=NULL;
do{
printf("=================================\n");
/* store the resultset */
result = mysql_store_result(&handle);
if(NULL == result){ /* if the resultset was null, 'continue' and get next resultset. */
printf("Empty resultset retrieved\n");
continue;
}
/* retrieve the first row */
MYSQL_ROW row = NULL;
while(row = mysql_fetch_row(result)) {
MYSQL_FIELD *mysqlFields = mysql_fetch_fields(result);
const char* field_name = mysqlFields[0].name;
/* get the length of the data of the first row in the 1st column of the resultset. */
unsigned long* field_lengths = mysql_fetch_lengths(result);
unsigned long field_length = field_lengths[0];
/* copy the data to a null terminated string buffer. */
char* fieldData = (char *)malloc(field_length + 1);
memset(fieldData, '\0', field_length + 1);
memcpy(fieldData, row[0], field_length);
/* output the results. */
printf("%s: %s.\n", field_name, fieldData);
/* perform memory cleanup. */
free(fieldData);
}
mysql_free_result(result);
}while(mysql_next_result(&handle) == 0);
/* free the resultset. */
mysql_free_result(result);
mysql_close(&handle);
return 0;
}

同样,下边是代码执行结果:
#gcc -I/usr/include/mysql 1.c -L/usr/lib/mysql -lmysqlclient -lpthread -lz -o 1.out
# ./1.out
goodmysql_real_query: SET @@max_sp_recursion_depth=3; SET @msg = '111111'; CALL agent_tree(@msg);
=================================
Empty resultset retrieved
=================================
Empty resultset retrieved
=================================
Account_number: 111111.
Account_number: 111112.
Account_number: 111115.
Account_number: 111117.
Account_number: 111113.
Account_number: 111116.
Account_number: 111114.
=================================
Empty resultset retrieved
#

其中在编写该段代码遇到的一些问题,在另外一个帖子中贴出来吧.


mysql网站第一帖--英文帖

今天在mysql forum发了第一篇帖子,而且是英文帖,并且帮助一位回答了问题,臭屁一下,blog记录一下:
地址为:http://forums.mysql.com/read.php?45,89240,89240#msg-89240

原帖为:

why can't retrieved result by call stored procedure using c api?

Posted by: wang fletcher (IP Logged)
Date: May 11, 2006 11:30PM

hello,everyone ,I am a new one from china.
I encounter a problem when i write a c code to test how to call stored procedure in mysql!
But I can't retrieved the results,the follow is the c source code:
int main(int argc, char* argv[])
{
MYSQL handle;
mysql_init(&handle);
if(!mysql_real_connect(&handle, "localhost", "root", NULL, "Geopacket", 0, NULL, CLIENT_MULTI_STATEMENTS CLIENT_MULTI_RESULTS)){
printf("mysql_real_connect error\n");
mysql_close(&handle);
return -1;
}
const char* sqlQuery = "SET @@max_sp_recursion_depth=100; SET @msg = '111111'; CALL agent_tree(@msg);";

if(mysql_real_query(&handle, sqlQuery, (unsigned long) strlen(sqlQuery))){
printf("mysql_real_query error\n");
mysql_close(&handle);
return -1;
}
printf("mysql_real_query: %s\n", sqlQuery);
MYSQL_RES* result=NULL;
do{
printf("=================================\n");
result = mysql_store_result(&handle);
if(NULL == result){
printf("Empty resultset retrieved\n");
continue;
}
MYSQL_ROW row = mysql_fetch_row(result);
if(row != NULL){
MYSQL_FIELD *mysqlFields = mysql_fetch_fields(result);
const char* field_name = mysqlFields[0].name;
unsigned long* field_lengths = mysql_fetch_lengths(result);
unsigned long field_length = field_lengths[0];
char* fieldData = (char *)malloc(field_length + 1);
memset(fieldData, '\0', field_length + 1);
memcpy(fieldData, row[0], field_length);
printf("%s: %s.\n", field_name, fieldData);
free(fieldData); } mysql_free_result(result);
}while(mysql_next_result(&handle) == 0);
mysql_free_result(result);
mysql_close(&handle);
return 0;
}

when I excute the code,this is the result:

#./a.out
mysql_real_query: SET @@max_sp_recursion_depth=100; SET @msg = '111111'; CALL agent_tree(@msg);
=================================
Empty resultset retrieved
=================================
Empty resultset retrieved
=================================
Account_number: 111111.
=================================
Empty resultset retrieved
#
But when I call the stored procedure in mysql command line,the return result is OK:

mysql> call agent_tree(@msg);
+----------------+--------+-----------+
Account_number Name Parent_id
+----------------+--------+-----------+
111111 host 000000
111112 Agent1 111111
111115 Agent4 111112
111117 Agent6 111115
111113 Agent2 111111
111116 Agent5 111113
111114 Agent3 111111
+----------------+--------+-----------+
7 rows in set (0.01 sec) Query OK, 0 rows affected, 1 warning (0.01 sec)

what's wrong? Are there some tips about calling stored procedure using c api?

please help me,thanks