Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » "simple" connection and operation with database
Re: "simple" connection and operation with database [message #55222 is a reply to message #55217] Tue, 20 October 2020 15:44 Go to previous message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi, this work!

(i.e. console)

#include <MySql/MySql.h>

using namespace Upp;

int main ( int argc, const char *argv[] )
{
MySqlSession session;

if ( session.Connect ( "root", "10", "test" ) )
{

Cout() << "Connected\n";
Sql sql ( session );

const String dq="\"";

try
{
sql.Begin();

for ( int i = 0; i < 10; i++ )
sql.Execute ( "insert into test_table(ID, VALUE) values (?, ?)", i, AsString ( 3 * i ) );

sql.Clear();

String a = "";

String b = "";

sql.Execute ( "SELECT * FROM test_table" );

while ( sql.Fetch() )
{
Value v;
sql.GetColumn ( 0, v );

b << AsString ( sql["ID"] ) + " , " + AsString ( sql["VALUE"] ) << "\n";
a += b;

}

LOG ( a );

sql.Clear();

sql.Execute ( "UPDATE test_table Set VALUE="+dq+"zero"+dq+" where VALUE="+dq+"9"+dq);

sql.Execute ( "DELETE FROM test_table where VALUE="+dq+"3"+dq+" or VALUE="+dq+"18"+dq);

sql.Commit();

}

catch ( SqlExc &ex )
{
Cerr() << "ERROR: " << ex << "\n";
SetExitCode ( 1 );
}
}

else
{

Cerr() << "ERROR: Unable to connect to database\n";

SetExitCode ( 1 );

}

SetExitCode ( 0 );
}

and from now on, the next step would be this example using SQL Schema Files!


 
Read Message
Read Message
Previous Topic: upload / download
Next Topic: Column Visible / hidden (arrayCtrl)
Goto Forum:
  


Current Time: Wed May 15 03:17:00 CEST 2024

Total time taken to generate the page: 0.03862 seconds