⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 insert_test.c

📁 《嵌入式Linux应用开发详解》中的源代码
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <time.h>#include <libmsql/msql.h>#define INSERT_QUERY "insert into test (name,num) values ('item %d', %d)"#define VERBOSEint main(argc,argv)	int	argc;	char	*argv[];{	unsigned int count, num;	int	sock,		oldTime,		curTime,		cur;	char	qbuf[160],		*host = NULL,		*db,		*qty;		if (argc != 3 && argc != 5)	{		printf("usage : insert_test [-h host] <dbname> <Num>\n\n");		exit(1);	}	if (argc == 5)	{		host = argv[2];		db = argv[3];		qty = argv[4];	}	else	{		host = NULL;		db = argv[1];		qty = argv[2];	}	if ((sock = msqlConnect(host)) < 0)	{		printf("Couldn't connect to engine!\n%s\n\n", msqlErrMsg);		perror("");		exit(1);	}	if (msqlSelectDB(sock,db) < 0)	{		printf("Couldn't select database %s!\n%s\n",argv[1],msqlErrMsg);	}	num = atoi(qty);	count = 0;	cur = 0;	oldTime = time(NULL);	while (count < num)	{		snprintf(qbuf,sizeof(qbuf),INSERT_QUERY,count,count);		if(msqlQuery(sock,qbuf) < 0)		{			printf("Query failed for count=%d(%s)\n",count,				msqlErrMsg);			printf("Inserted %d rows\n",count);			exit(1);		}		count++;		cur++;		if (cur == 5000)		{#ifdef VERBOSE			curTime = time(NULL);			printf("%d  (%d seconds)\n",count, curTime - oldTime);			oldTime = curTime;#endif			cur = 0;		}	}	msqlClose(sock);	exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -