📄 connectradius.cpp
字号:
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
//#include <stdio.h>
#include "Database.h"
struct MyStruct
{
unsigned long min;
unsigned long max;
char front[11];
}UseStr;
MyStruct CompareChar(char MinID[11],char MaxID[11])
{ char remember[11];
char min[11];
char max[11];
for(int i=0;MinID[i]==MaxID[i];i++)
{
remember[i]=MinID[i];
}
remember[i]='\0';
for(int j=0;(11-i)>0;j++)
{
min[j]=MinID[i];
max[j]=MaxID[i];
i++;
}
UseStr.min=atol(min);
UseStr.max=atol(max);
strncpy(UseStr.front,remember,sizeof(UseStr.front));
return UseStr;
}
int strlenth(char *s)
{ int k=strlen(s);
for(int i=0;i<=k;i++)
{
if(s[i]=='\0')
break;
}
return i;
}
void strconnect(char *S,char *T)
{
if(S==NULL||T==NULL)
return;
int i,j,k=strlenth(S);
j=strlen(T);
for(i=0;i<=j;i++)
S[i+k]=T[i];
S[i+k]='\0';
}
void main()
{
CDatabase *Radius=new CDatabase;
Database_Param pBaseParam;
Data_Param pDataParam;
char MinID[11],MaxID[11];
char host[16],user[20],password[50];
unsigned long MinRecord;
unsigned long MaxRecord;
char str[500]="";
char userID[11]="";
char temp[11];
int affect=0;
MyStruct result;
pBaseParam.host="192.168.3.122";
pBaseParam.user="machengqi";
pBaseParam.password="123456";
pBaseParam.db="ser";
pBaseParam.port=0;
pBaseParam.unix_socket=NULL;
pBaseParam.client_flag=0;
pDataParam.col_name="username";
pDataParam.db_name="ser";
pDataParam.insert_val="MD5('123'),8001,'MINGTEL.BIZ','9186','8001@9186.BIZ',now()";
pDataParam.select_exp="*";
pDataParam.set_exp="username";
pDataParam.tab_name="subscriber(phplib_id,username,domain,password,email_address,datetime_created)";
pDataParam.where_def="username>8001";
/* MYSQL_ROW strRecord;
unsigned int num_fields;
unsigned int i=0;
int NewCount;
Radius->SelectRecord(&pDataParam); //得到记录集
num_fields=Radius->GetFieldNum(); //得到列的数量
while((strRecord=Radius->GetRecord()))
{
unsigned long *lengths;
lengths=Radius->FetchLengths(); //返回列的长度
for(i=0;i<num_fields;i++)
{
printf("\t%.*s",(int)lengths[i],strRecord[i]?strRecord[i]:"NULL");
}
printf("\n");
}
NewCount=Radius->GetAffectedRows();
Radius->FreeRecord(); //释放记录集
printf("\n");
printf("影响记录的行数为:%d",NewCount);
cout<<endl;*/
cout<<"请输入主机的IP地址:"<<endl;
cin>>host;
cout<<"请输入用户名:"<<endl;
cin>>user;
cout<<"请输入密码:"<<endl;
cin>>password;
pBaseParam.host=host;
pBaseParam.user=user;
pBaseParam.password=password;
if(Radius->ConnectDB(&pBaseParam))
printf("连接成功!");
cout<<endl;
cout<<"请输入ID号的下限:"<<endl;
cin>>MinID;
cout<<"请输入ID号的上限:"<<endl;
cin>>MaxID;
result=CompareChar(MinID,MaxID);
MinRecord=result.min;
MaxRecord=result.max;
cout<<"正在插入,请稍等..."<<endl;
while(MinRecord<=MaxRecord)
{ int record;
itoa(MinRecord,temp,10);
strncpy(userID,result.front,sizeof(userID));
strncat(userID,temp,sizeof(userID));
sprintf(str,"MD5(%s),%s,'gtalkie.com','9186','%s@gtalkie.com',now()",userID,userID,userID);
pDataParam.insert_val=str;
Radius->InsertRecord(&pDataParam);
record=Radius->GetAffectedRows();
affect+=record;
MinRecord++;
}
cout<<endl;
cout<<"影响的行数为:"<<affect<<endl;
getchar();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -