ProudNet.Eng
WebsiteProud ConsoleLanguage
  • 🌐ProudNet
    • ProudNet Introduction
    • Download and Install
      • How to verify your ProudNet license
      • AMI
    • Project Settings
      • C++
      • C#
      • Mac Xcode
      • Linux
      • Unity3D
        • iOS Build
      • Unreal Engine 4
      • Running the PIDL Compiler
    • Using ProudNet
      • Server and Client
        • Utilization of Server
        • Utilization of Client
      • RMI
        • Utilization of RMI
      • PIDL
        • Utilization of PIDL
      • Event handling
      • Communication messages
      • P2P Communication
        • Using P2P communication
    • Utilization of ProudNet
      • How to use
      • Tips for performance
    • Using DB in ProudNet
      • DB Cache System ver.2
        • DB Cache Theory and Understanding
        • Install DB Cache and Set Up Network
        • DB Cache Server and Client
        • DB Cache usage and application
          • Utilization of DB Cache
      • ADO API
      • ODBC API
    • ProudNet Utility
  • ProudNet Note
    • Technical Notes
      • Main Loop
      • Setting up a server firewall
      • Encryption and decryption
      • What to do in case of an error
      • List of error messages
      • Synchronizing Character Position
      • Client-Server Communication
      • MiniDump (Error Dump System)
      • [Version 1.6] Server-to-Server LAN Communicator
    • Glossary
    • Sample examples
  • 🌐Proud Service
    • Guide for Console
    • ProudChat
      • Download SDK
        • C++
        • C#
        • Unity3D
        • Unreal Engine 4
      • Features in Console
Powered by GitBook
On this page
  • Connecting to DB
  • Using DB
  • - Using Query directly
  • - Using stored procedures
  • - Reading CAdoRecordset Data
  1. ProudNet
  2. Using DB in ProudNet

ADO API

PreviousUtilization of DB CacheNextODBC API

Last updated 1 year ago

The ADO Wrapper API in ProudNet DB is an API designed to easily handle Microsoft ActiveX Data Object (ADO) in C++ language, making it easier to access DBMS using ADO.

The code below is illustrated based on the .

Connecting to DB

The syntax entered as a parameter to the Open function follows the rules.

Proud::CAdoConnection conn;

// MSSQL
conn.Open(L"Driver={ODBC Driver 17 for SQL Server};Server=localhost;Database=ProudAdo-Test;Trusted_Connection=yes;");
// MYSQL
conn.Open(L"Driver={MySQL ODBC 8.0 Unicode Driver};Server=127.0.0.1;Port=3306;Database=proudado-test;User ID=proud;Password=proudnet123;Option=3;", Proud::DbmsType::MySql);

Using DB

- Using Query directly

// A query for testing.
// To use this query, 
// a UserData table with columns named UserId, Password,
// and Country must exist in the DB.


// Transaction starts
conn.BeginTrans();

// Query execution code
// The example below is a query for testing purposes.
// To use this query, 
// a UserData table with columns named UserId, Password, 
// and Country must exist in the DB.
conn.Execute(Proud::String::NewFormat(L"insert into UserData (UserID, Password, Country) VALUES(%s, %s, %d)", L"test", L"password", 1));

// Transaction commit
conn.CommitTrans();

- Using stored procedures

// CAdoCommand to hold the statement information 
Proud::CAdoCommand cmd;
// CAdoRecordset to hold the return data
Proud::CAdoRecordset rec;

// A procedure called AddUserData must exist.
cmd.Prepare(conn, L"AddUserData");

// Add a parameter.
cmd.Parameters[1] = L"test";
cmd.Parameters[2] = L"password";
cmd.Parameters[3] = 1;

// Execute the procedure
cmd.Execute(rec);

rec.Close();
// CAdoCommand to hold the statement information 
Proud::CAdoCommand cmd;
// CAdoRecordset to hold the return data
Proud::CAdoRecordset rec;

// A procedure called AddUserData must exist.
cmd.Prepare(conn, L"AddUserData");

// Unlike MSSQL, you must call AppendParameter.
// Need to call AppendParameter instead of MSSQL.
cmd.AppendParameter(L"InUserID", ADODB::adVarWChar, ADODB::adParamInput, L"test", wcslen(L"test"));
cmd.AppendParameter(L"InPassword", ADODB::adVarWChar, ADODB::adParamInput, L"password", wcslen(L"password"));
cmd.AppendParameter(L"InCountry", ADODB::adInteger, ADODB::adParamInput, 1);

cmd.Execute();

rec.Close();

- Reading CAdoRecordset Data

Proud::AdoRecordset rec;
// Similarly, the UserData table must exist in the DB.
rec.Open(conn, Proud::DbOpenFor::OpenForReadWrite, L"select * from UserData");

Proud::String strID, strPassword, strCountry;
while (rec.IsEOF() == false)
{
	strID = ((Proud::String)rec.FieldValues[L"UserID"]).GetString();
	strPassword = ((Proud::String)rec.FieldValues[L"Password"]).GetString();
	strCountry = ((Proud::String)rec.FieldValues[L"Country"]).GetString();
	
	wprintf(L"UserID : %s, Password : %s, Country : %s\n", strID.GetString(), strPassword.GetString(), strCountry.GetString());
	
	rec.MoveNext();
}
Proud::AdoRecordset rec;
// Similarly, the UserData table must exist in the DB.
rec.Open(conn, Proud::DbOpenFor::OpenForReadWrite, L"select * from UserData");

Proud::String strID, strPassword, strCountry;
while (rec.IsEOF() == false)
{
	strID = rec.FieldValues[L"UserID"];
	strPassword = rec.FieldValues[L"Password"];
	strCountry = rec.FieldValues[L"Country"];
	
	wprintf(L"UserID : %s, Password : %s, Country : %s\n", strID.GetString(), strPassword.GetString(), strCountry.GetString());
	
	rec.MoveNext();
}

🌐
git example project
Connection Strings