月度归档:2015年07月

read扩展 健壮地读--有缓冲

代码:
#include < stdio.h>
#include < fcntl.h>
#include < unistd.h>
#include < sys/types.h>
#include < sys/uio.h>
#include < string.h>

typedef struct{
int rio_fd;
int rio_cnt;
char *rio_bufptr;
char rio_buf[8192];
} rio_t;

void rio_readinitb(rio_t *rp,int fd);
ssize_t rio_read(rio_t *rp,char *usrbuf,size_t n);
ssize_t rio_readlineb(rio_t *rp,void *usrbuf,size_t maxlen);

int main(){
int fd;
char buf[1000];
rio_t fd2;
fd =open(“a.txt”,’r’);
if(fd <=0) { printf("open file error!"); return 0; } rio_readinitb(&fd2,fd); if(rio_readlineb(&fd2,buf,8192) >0)
{
printf(“file information:%s!\n”,buf);
}

close(fd);

}

void rio_readinitb(rio_t *rp,int fd){
rp->rio_fd = fd;
rp->rio_cnt = 0;
rp->rio_bufptr = rp->rio_buf;
}

ssize_t rio_read(rio_t *rp,char *usrbuf,size_t n){
int cnt;

while(rp->rio_cnt <=0){ rp->rio_cnt = read(rp->rio_fd,rp->rio_buf,sizeof(rp->rio_buf));
if(rp->rio_cnt <0) { return -1; }else if(rp->rio_cnt ==0)
return 0;
else
rp->rio_bufptr = rp->rio_buf;
}

cnt = n;
if(rp->rio_cnt rio_cnt;
}

memcpy(usrbuf,rp->rio_bufptr,cnt); //缓冲方法

rp->rio_bufptr +=cnt;
rp->rio_cnt -=cnt;

return cnt;

}

ssize_t rio_readlineb(rio_t *rp,void *usrbuf,size_t maxlen){
int n,rc;
char c,*bufp = usrbuf;

for(n=1 ; n < maxlen ;n++){ if(( rc = rio_read(rp,&c,1))==1){ *bufp++ =c; if( c =='\n'){ break; }else if(rc ==0){ if(n==1){ return 0; }else break; } }else{ return -1; } } *bufp =0; return n; }

如何查询MSSQL 当前进程及数据库中的并发进程


一、可以采用

sp_who //获取MSSQl中的进程
sp_who active //获取MSSQl中的活动的进程

二、采用

sp_lock //获取当前数据库 阻塞的表


三、通过 下列SQL语句获取活动的进程


select request_session_id as spid,
OBJECT_NAME(resource_associated_entity_id) as tableName
from sys.dm_tran_locks where resource_type=’OBJECT’
and OBJECT_NAME(resource_associated_entity_id) is not null
order by request_session_id asc

mssql

————————-
dbcc inputbuffer(spid) //来获取进程id 所对应的sql 或者存储过程

如何向自增列中插入数据(mssql)

如何向自增列中插入数据?


一、新建表

create table test(id int identity,a varchar(50))
create table test1(id int identity,a varchar(50))


二、初始化数据

insert into test (a)values(‘a’)
insert into test (a)values(‘b’)
insert into test (a)values(‘c’)
insert into test (a)values(‘d’)
insert into test (a)values(‘e’)
insert into test (a)values(‘f’)
insert into test (a)values(‘g’)
insert into test (a)values(‘h’)
insert into test (a)values(‘i’)
insert into test (a)values(‘j’)


三、检测数据情况

select * from test


四、向自增列表插入数据
{注意事项:插入时列名必须写入,不然会报错}

set IDENTITY_INSERT test1 on
insert into test1(id,a) select ID,a from test
set IDENTITY_INSERT test1 off


五、检测数据插入情况,再次向新表插入数据,检测自增列的增长情况

select * from test1

insert into test1(a)values(‘sdfsf’)

select * from test1