INSERT INTO `user_wealth`(`UserID`,`Gold`,`Point`,`Experience`,`Feats`,`GameCoin`,`anti_addiction_time`,`anti_addiction_play_time`,`WinCount`,`LostCount`,`Revenue`)
VALUES (100,40000,20,0,70910,0,1382492756,359,10,13,528),(101,40000,-450,0,0,0,1382497686,14,3,2,343);
UPDATE user_wealth SET Gold=40000 WHERE userid>=10 && userid<=99
UPDATE user_wealth SET POINT=0 WHERE userid>=100 && userid<=139
UPDATE user_wealth SET Feats=0 WHERE userid>=100 && userid<=139
机器人账号T100-T139的密码由123改为1234
UPDATE user_info SET PASSWORD='81DC9BDB52D04DC20036DBD8313ED055' WHERE userid>=100 AND userid<=139
//操作MDB文件的小工具MdbTool.exe
#include <afxwin.h>
#include <afxdao.h>
#include <string>
using namespace std;
BOOL __stdcall ExecuteDeleteAllRecords(char *strDBQ,char *strTable)
{
try
{
CDaoDatabase db;
string strSQL=strTable;
strSQL="delete from "+strSQL;
db.Open(strDBQ);
db.Execute(strSQL.c_str());
db.Close();
}
catch(CDaoException * pe)
{
AfxDaoTerm();
return FALSE;
}
AfxDaoTerm();
return TRUE;
}
BOOL __stdcall ExecuteDropTable(char *strDBQ,char *strTable)
{
try
{
CDaoDatabase db;
string strSQL=strTable;
strSQL="DROP TABLE "+strSQL;
db.Open(strDBQ);
db.Execute(strSQL.c_str());
db.Close();
}
catch(CDaoException * pe)
{
AfxDaoTerm();
return FALSE;
}
AfxDaoTerm();
return TRUE;
}
BOOL __stdcall ExecuteSQL(char *strDBQ,char *strSQL)
{
try
{
CDaoDatabase db;
db.Open(strDBQ);
db.Execute(strSQL);
db.Close();
}
catch(CDaoException * pe)
{
AfxDaoTerm();
return FALSE;
}
AfxDaoTerm();
return TRUE;
}
int main(int argc, char* argv[])
{
char sz[100]={0};
char sz1[100]={0};
char sz2[100]={0};
if(argc<2)
{
printf("请输入mdb文件名:");
scanf("%s",sz);
}
else
strcpy(sz,argv[1]);
if(argc<3)
{
printf("请输入表名或SQL语句(例如CREATE TABLE ThisTable(FirstName TEXT, LastName TEXT);):");
scanf("%s",sz1);
}
else
strcpy(sz1,argv[2]);
if(argc<4)
{
printf("请选择:1.删除表中所有记录;2.删除表;3.SQl语句:");
scanf("%s",sz2);
}
else
strcpy(sz2,argv[3]);
int iflag=atoi(sz2);
if(iflag==1)
{
BOOL ret=ExecuteDeleteAllRecords(sz,sz1);
if(ret==TRUE)
::MessageBox(NULL,"删除表中记录完毕", "", MB_OK) ;
}
else if(iflag==2)
{
BOOL ret=ExecuteDropTable(sz,sz1);
if(ret==TRUE)
::MessageBox(NULL,"删除表完毕", "", MB_OK) ;
}
else if(iflag==3)
{
BOOL ret=ExecuteSQL(sz,sz1);
if(ret==TRUE)
::MessageBox(NULL,"执行SQL语句完毕", "", MB_OK) ;
}
system("pause");
return 0;
}
//Compact.exe----压缩MDB文件
//Win7+VC2010编译,by Ivan_han 20130626
#include "afxwin.h"
#import "C:\Program Files (x86)\Common Files\System\ado\msado20.tlb" no_namespace rename("EOF", "adoEOF")
#import "C:\Program Files (x86)\Common Files\System\ado\MSJRO.DLL"
int main(int argc, char* argv[])
{
char sz[100]={0};
char sz1[100]={0};
if(argc<2)
{
printf("请输入mdb文件名:");
scanf("%s",sz);
}
else
strcpy(sz,argv[1]);
strcpy(sz1,sz);
sz1[strlen(sz1)]='1';
CoInitialize(NULL);
CString strSrcConn,strDestConn;
strSrcConn.Format("Provider=Microsoft.JET.OLEDB.4.0;Data Source=%s;Jet OLEDB:Database Password=%s",sz,"");
strDestConn.Format("Provider=Microsoft.JET.OLEDB.4.0;Data Source=%s;Jet OLEDB:Database Password=%s",sz1,"");
try
{
JRO::IJetEnginePtr jet(__uuidof(JRO::JetEngine));
jet->CompactDatabase((LPCTSTR)strSrcConn, (LPCTSTR)strDestConn);
}
catch(_com_error &e)
{
::MessageBox(NULL, (LPCTSTR)e.Description( ), "", MB_OK) ;
}
::DeleteFile(sz);
::MoveFile(sz1,sz);
::MessageBox(NULL,"压缩Access数据库完毕", "", MB_OK) ;
CoUninitialize();
system("pause");
return 0;
}
ADO读写本机或远程64位MySQL的配置和示例
99服务器:Windows Server 2008 R2 Enterprise 64位+MySQL Server 5.5 64位
本机:Win7旗舰版 64位+MySQL Server 5.5 64位
本机myodbc 64位:mysql-connector-odbc-5.2.5-winx64.msi
本机VC2010程序用x64编译运行
本机VBS脚本64位解释运行
64wscript.bat
start C:\windows\system32\wscript mysql.vbs
或
64cscript.bat
start C:\windows\system32\cscript mysql.vbs
不用
32wscript.bat
start C:\windows\SysWOW64\wscript mysql.vbs
32cscript.bat
start C:\windows\SysWOW64\cscript mysql.vbs
mysql.vbs示例
Dim Cnn
Dim Rst
Dim strCnn
'使用StrCnn句柄连接数据库,
'StrCnn="DRIVER={MySQL ODBC 3.51 Driver};SERVER=127.0.0.1;PORT=3306;DATABASE=mysql; USER=root;PASSWORD=123;OPTION=3;"'WINXP+MySQL55下连接成功
StrCnn="DRIVER={MySQL ODBC 5.2 ANSI Driver};SERVER=192.168.1.99;PORT=3306;DATABASE=mysql; USER=root;PASSWORD=mysql55;OPTION=3;"'WIN7+MySQL55下连接成功
'StrCnn="DSN=myODBCdsn;DRIVER={MySQL ODBC 5.2 ANSI Driver};SERVER=127.0.0.1;UID=root;PWD=mysql55;DATABASE=mysql;PORT=3306;OPTION=3;"
'创建连接对象
Set Cnn = CreateObject("ADODB.Connection")
Cnn.Open strCnn '使用Cnn对象方法打开 StrCnn
'查看是否连接成功,成功状态值为1
'msgbox Conn.state
If Cnn.State = 0 Then
msgbox "连接数据库失败"
else
msgbox "连接数据库成功"
End If
Dim strQuery '查询句柄
strQuery = "select * from help_topic"
Set Rst = Cnn.Execute(strQuery) '创建查询句柄对象
If Not Rst.BOF Then
WScript.Echo Rst("help_topic_id")
WScript.Echo Rst("name")
Else
MsgBox "数据为空"
End If
MsgBox "点击结束"
VC2010示例
#include"StdAfx.h"
#include<afxwin.h>
#import "c:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF", "EndOfFile")
/*
'StrCnn="DRIVER={MySQL ODBC 3.51 Driver};SERVER=127.0.0.1;PORT=3306;DATABASE=mysql; USER=root;PASSWORD=123;OPTION=3;"'WINXP+MySQL55下连接成功
StrCnn="DRIVER={MySQL ODBC 5.2 ANSI Driver};SERVER=127.0.0.1;PORT=3306;DATABASE=mysql; USER=root;PASSWORD=mysql55;OPTION=3;"'WIN7+MySQL55下连接成功
help_topic_id 19
name 129
help_category_id 18
description 201
example 201
url 129
注意,用x64编译,不要用Win32编译,否则出现如下错误:
Description = '[Microsoft][ODBC 驱动程序管理器] 在指定的 DSN 中,驱动程序和应用程序之间的体系结构不匹配'
*/
int main(int argc, char* argv[])
{
printf("使用ADO读写Mysql数据库,需要安装Mysql的ODBC驱动(myodbc3.dll、myodbc3S.dll)\n");
CoInitialize(NULL);
try
{
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset");
//采用myodbc 连接mysql
//pConn->Open("DSN=myODBCdsn;DRIVER={MySQL ODBC 5.2 ANSI Driver};SERVER=127.0.0.1;UID=root;PWD=mysql55;DATABASE=mysql;PORT=3306;OPTION=3;","","",adConnectUnspecified);
pConn->Open("DRIVER={MySQL ODBC 5.2 ANSI Driver};SERVER=192.168.1.99;PORT=3306;DATABASE=mysql; USER=root;PASSWORD=mysql55;OPTION=3;","","",adConnectUnspecified);
//Open "help_topic" table
pRst->Open("help_topic", _variant_t((IDispatch *) pConn, true),
adOpenStatic, adLockReadOnly, adCmdTable);
FieldsPtr fds=pRst->GetFields();
printf("printf field name of the table\n");
for(int i=0;i<fds->GetCount();i++)
{
FieldPtr fd=fds->GetItem(_variant_t(short(i)));
printf("%s ",(LPCTSTR)fd->GetName());
printf("%d\n ",fd->GetType());
}
printf("\n");
pRst->Close();
pConn->Close();
}
catch (_com_error &e)
{
printf("Description = '%s'\n", (char*) e.Description());
}
::CoUninitialize();
system("pause");
return 0;
}
使用ADO读写Mysql数据库,需要安装Mysql的ODBC驱动(myodbc3.dll、myodbc3S.dll)
printf field name of the table
ID 19
AccountName 200
Password 129
Asker 200
PlayerType 16
RealName 200
IDCard 129
IDCardIsInvalid 16
Email 200
Question 16
Answer 200
RegDate 135
RegIP 200
Active 16
Partner 200
Ticket 3
FreezeDate 3
AskerId 3
ActiveTime 135
#include <afxwin.h>
#import "c:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF", "EndOfFile")
int main(int argc, char* argv[])
{
printf("使用ADO读写Mysql数据库,需要安装Mysql的ODBC驱动(myodbc3.dll、myodbc3S.dll)\n");
CoInitialize(NULL);
try
{
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset");
//采用myodbc 连接mysql
pConn->Open("DRIVER={MySQL ODBC 3.51 Driver};SERVER=192.168.1.108; DATABASE=kp_accounts;UID=root;PWD=root; OPTION=3"
//pConn->Open("PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=F:\\Data阅读\\ch.mdb;UID=;"
//pConn->Open("Provider= Microsoft.Jet.OLEDB.4.0;Data Source=F:\\Data阅读\\ch.mdb;"//this is also OK
,"","",adConnectUnspecified);
//Open "accounts" table
pRst->Open("accounts", _variant_t((IDispatch *) pConn, true),
adOpenStatic, adLockReadOnly, adCmdTable);
FieldsPtr fds=pRst->GetFields();
printf("printf field name of the table\n");
for(int i=0;i<fds->GetCount();i++)
{
FieldPtr fd=fds->GetItem(_variant_t(short(i)));
printf("%s ",(LPCTSTR)fd->GetName());
printf("%d\n ",fd->GetType());
}
printf("\n");
pRst->Close();
pConn->Close();
}
catch (_com_error &e)
{
printf("Description = '%s'\n", (char*) e.Description());
}
::CoUninitialize();
system("pause");
return 0;
}
Dim Ca
Set Ca = WScript.CreateObject("ADOX.Catalog")
'建立数据库文件Access97 or Access2000
'Ca.Create("Provider=Microsoft.Jet.OLEDB.3.51;Data Source=D:\DBTest\GSGameUserDB.mdb")
Ca.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\DBTest\GSGameUserDB.mdb")
Set Ca=Nothing
WScript.Echo "CREATE GSGameUserDB.mdb OK!"
Dim oConn,sConnStr,strSQL
sConnStr="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=D:\DBTest\GSGameUserDB.mdb;Persist Security Info=false;Jet OLEDB:System database=D:\DBTest\system.mdw"
Set oConn=WScript.CreateObject("ADODB.Connection")
oConn.Open sConnStr
strSQL="CREATE TABLE PlayerAccouts "&_
"([PlayerID] INTEGER,"&_
"[Accouts] TEXT(12),"&_
"[LogonPass] TEXT(12),"&_
"[Online] BIT,"&_
"[FaceID] INTEGER,"&_
"[NickName] TEXT(20),"&_
"CONSTRAINT [Index1] PRIMARY KEY ([PlayerID]));"
oConn.Execute strSQL
oConn.Close
Set oConn=Nothing
WScript.Echo "CREATE TABLE PlayerAccouts OK!"
Dim Ca
Set Ca = WScript.CreateObject("ADOX.Catalog")
'建立数据库文件Access97 or Access2000
'Ca.Create("Provider=Microsoft.Jet.OLEDB.3.51;Data Source=D:\DBTest\TestDB.mdb")
Ca.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\DBTest\TestDB.mdb")
Set Ca=Nothing
WScript.Echo "CREATE TestDB.mdb OK!"
Dim oConn,sConnStr,strSQL
sConnStr="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=D:\DBTest\TestDB.mdb;Persist Security Info=false;Jet OLEDB:System database=D:\DBTest\system.mdw"
Set oConn=WScript.CreateObject("ADODB.Connection")
oConn.Open sConnStr
strSQL="CREATE TABLE T_Employee "&_
"([EmployeeID] TEXT,"&_
"[Name] TEXT,"&_
"[Rank] TEXT);"
oConn.Execute strSQL
oConn.Close
Set oConn=Nothing
WScript.Echo "CREATE TABLE T_Employee OK!"
Dim oConn,sConnStr,strSQL
sConnStr="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=D:\DBTest\TestDB.mdb;Persist Security Info=false;Jet OLEDB:System database=D:\DBTest\system.mdw"
Set oConn=WScript.CreateObject("ADODB.Connection")
oConn.Open sConnStr
strSQL="INSERT INTO T_Employee values ('000','刘德华','主管');"
oConn.Execute strSQL
strSQL="INSERT INTO T_Employee values ('001','张学友','主管');"
oConn.Execute strSQL
strSQL="INSERT INTO T_Employee values ('053','万芳','');"
oConn.Execute strSQL
oConn.Close
Set oConn=Nothing
WScript.Echo "INSERT INTO T_Employee OK!"
Dim Ca
Set Ca = WScript.CreateObject("ADOX.Catalog")
'建立数据库文件Access97 or Access2000
'Ca.Create("Provider=Microsoft.Jet.OLEDB.3.51;Data Source=D:\DBTest\QPSiSeQiuDB.mdb")
Ca.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\DBTest\QPSiSeQiuDB.mdb")
Set Ca=Nothing
WScript.Echo "CREATE QPSiSeQiuDB.mdb OK!"
Dim oConn,sConnStr,strSQL
sConnStr="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data
Source=D:\DBTest\QPSiSeQiuDB.mdb;Persist Security Info=false;Jet OLEDB:System
database=D:\DBTest\system.mdw"
Set oConn=WScript.CreateObject("ADODB.Connection")
oConn.Open sConnStr
strSQL="CREATE TABLE IssueInfo "&_
"([IssueID] INTEGER,"&_
"[BallNumber] BYTE,"&_
"[Finish] BYTE,"&_
"[FinishDate] DATETIME,"&_
"[CreateDate] DATETIME,"&_
"CONSTRAINT [Index1] PRIMARY KEY ([IssueID]));"
oConn.Execute strSQL
oConn.Close
Set oConn=Nothing
WScript.Echo "CREATE TABLE IssueInfo OK!"
Dim oConn,sConnStr,strSQL
sConnStr="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data
Source=D:\DBTest\QPSiSeQiuDB.mdb;Persist Security Info=false;Jet OLEDB:System
database=D:\DBTest\system.mdw"
Set oConn=WScript.CreateObject("ADODB.Connection")
oConn.Open sConnStr
'strSQL="INSERT INTO IssueInfo values (121100001,7,1,'2012-11-01 17:10','2012-11-01 14:10');"
'oConn.Execute strSQL
'strSQL="INSERT INTO IssueInfo values (121100002,3,1," & 123 & "," & 456 & ");"
'oConn.Execute strSQL
for i=1 to 12
strSQL="INSERT INTO IssueInfo values (" & 121100002+i & "," & i & ",1," & CDbl(DateAdd("s",30,Now))
& "," & CDbl(Now) & ");"
oConn.Execute strSQL
next
oConn.Close
Set oConn=Nothing
WScript.Echo "INSERT INTO IssueInfo OK!"
'功能:VBS访问SQL Server 2005数据库
dim conn
set conn=WScript.CreateObject("ADODB.Connection")
conn.Open "Driver={SQL Server};server=192.168.1.108;database=QPSiSeQiuDB;uid=sa;pwd=123;"
dim rst
set rst=WScript.CreateObject("ADODB.Recordset")
sSQL="select top 20 * from dbo.IssueInfo;"
rst.open sSQL,conn,1,1
if rst.eof and rst.bof then
WScript.Echo "没有记录"
else
do while not rst.eof
WScript.Echo rst("IssueID") & " " & rst("BallNumber") & " " & rst("Finish") & " " & rst
("FinishDate") & " " & rst("CreateDate")
rst.movenext
loop
end if
WScript.Sleep 4000
WScript.QUIT
rst.close
set rst=nothing
conn.close
set conn=thing
ALTER PROCEDURE [dbo].[SSQ_OUT_Test] AS
--没开奖数量
SELECT COUNT(*) as cnt FROM IssueInfo WHERE Finish=0
'功能:VBS执行SQL Server 2005数据库中的存储过程
dim conn
set conn=WScript.CreateObject("ADODB.Connection")
conn.Open "Driver={SQL Server};server=192.168.1.108;database=QPSiSeQiuDB;uid=sa;pwd=123;"
dim rst
'正确的写法1:
'dim vRe
'set rst=conn.Execute("EXEC SSQ_OUT_TEST",vRe,1)
'正确的写法2:
set rst=WScript.CreateObject("ADODB.Recordset")
'或rst.open "EXEC SSQ_OUT_TEST",conn,1,1
'或rst.open "SSQ_OUT_TEST",conn,1,1
rst.open "SSQ_OUT_TEST",conn
if rst.eof and rst.bof then
WScript.Echo "没有记录"
else
do while not rst.eof
'WScript.Echo rst("cnt")
WScript.Echo rst(0)
rst.movenext
loop
end if
WScript.Sleep 4000
WScript.QUIT
rst.close
set rst=nothing
conn.close
set conn=thing
'功能:VBS执行SQL Server 2005数据库中的存储过程
dim conn
set conn=WScript.CreateObject("ADODB.Connection")
conn.Open "Driver={SQL Server};server=192.168.1.108;database=QPSiSeQiuDB;uid=sa;pwd=123;"
dim rst
'正确的写法1:
dim vRe
set rst=conn.Execute("EXEC SSQ_OUT_GetUserScore_Info 4084",vRe,1)
'正确的写法2:
'set rst=WScript.CreateObject("ADODB.Recordset")
'rst.open "EXEC SSQ_OUT_GetUserScore_Info 4084",conn,1,1
'或rst.open "SSQ_OUT_GetUserScore_Info 4084",conn,1,1
'或rst.open "SSQ_OUT_GetUserScore_Info 4084",conn
if rst.eof and rst.bof then
WScript.Echo "没有记录"
else
do while not rst.eof
'WScript.Echo rst("cnt")
WScript.Echo rst(0) & "," & rst(1) & "," & rst(2) & "," & rst(3)
rst.movenext
loop
end if
WScript.Sleep 4000
WScript.QUIT
rst.close
set rst=nothing
conn.close
set conn=thing