delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/06/26/17:15:28

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
From: "David Ayliffe" <me AT ayliffe DOT com>
To: <cygwin AT cygwin DOT com>
Subject: Welcome and here's your C++ starter for 10
Date: Tue, 26 Jun 2001 21:31:46 +0100
Message-ID: <!~!UENERkVCMDkAAQACAAAAAAAAAAAAAAAAABgAAAAAAAAA0HAidKTJfky/qbjgn6Tt0cKAAAAQAAAAQ85oT+TEJ0iyrGXc4aynnwEAAAAA@ayliffe.com>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook, Build 10.0.2616
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2465.0003
Importance: Normal
Disposition-Notification-To: "David Ayliffe" <me AT ayliffe DOT com>

------=_NextPart_000_000C_01C0FE87.67E20680
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Just a little note to say hello to all.  This is my first post to this
mailing list.  I am a complete newbie to porting apps and I need some
advice.  I have this CPP program (attached) which simply connects to a
mysql server, issues a query and exits.  Ideally I need to port this to
Linux, is this possible?

Is it possible to port CPP code to another platform e.g. Linux (under
Pentium). Can anyone see any difficulties in porting this code. Is
cygwin the tool for this or do I need some other program.


Sorry about the read receipt; I'm just getting a feel for how many
people are on this mailing list.

I would appreciate ANY advice going, and I thank you for your time.


Thanks lots
David Ayliffe (mail AT ayliffe DOT com)

------=_NextPart_000_000C_01C0FE87.67E20680
Content-Type: application/octet-stream;
	name="dummy1.cpp"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="dummy1.cpp"

#include <iostream>=0A=
#include <iomanip>=0A=
#include "include\mysql++"=0A=

//Connection(cchar *db, cchar *host=3D"",cchar *user=3D"", cchar =
*passwd=3D"")=20
#define def_host_name	"localhost"      // host to connect to (default =
localhost)=20
#define def_user_name	"admin"           // user name for db (default =
login name)=20
#define def_password	""               // password for the db (default is =
null)=20
#define def_db_name		"mysql_cpp_data" // default db name (default none)=20
#define def_svr_port	"3066"           // port to connect to (defualt =
3306)=20

void QueryDatabases();
void ExecQuery(string sQuery);
=0A=
int main()=20
{=0A=
  try=20
  {=0A=
		Connection con(def_db_name, def_host_name, def_user_name, =
def_password);=0A=
		Query query =3D con.query();=0A=
		// This creates a query object that is bound to con.=0A=
=0A=
		query << "select * from stock";		=0A=
		// You can write to the query object like you would any other ostrem	=09
	=09
		cout << "Query: " << query.preview() << endl;
		// Show the query before it is executed=0A=
		// Query::preview() simply returns a string with the current query
		// string in it.
	=09
		Result res =3D query.store();
=0A=
		// Query::store() executes the query and returns the results=0A=
  =0A=
		Row row;=0A=
		cout.setf(ios::left);=0A=
		cout << setw(17) << "Item" =0A=
			<< setw(4)  << "Num"=0A=
			<< setw(7)  << "Weight"=0A=
			<< setw(7)  << "Price" =0A=
			<< "Date" << endl=0A=
			<< endl;
=0A=
		Result::iterator i;=0A=
		// The Result class has a read-only Random Access Iterator=0A=
		for (i =3D res.begin(); i !=3D res.end(); i++)=20
		{		=09
			row =3D *i;

			// you can use either the index number or column name when
			// retrieving the colume data
			cout << setw(17) << row[0] =0A=
				<< setw(4)  << row[1] =0A=
				<< setw(7)  << row[2]=0A=
				<< setw(7)  << row[3]=0A=
				<< row[4] << endl;			=0A=
		}
		cout << endl << "Records Found: " << res.size() << endl;

		QueryDatabases();
//		ExecQuery("select * from stock");
		ExecQuery("show databases");
		=0A=
  } catch (BadQuery er)
  { // handle any connection or query errors that may come up=0A=
    cerr << "Error: " << er.error <<  endl;=0A=
    return -1;=0A=
=0A=
  } catch (BadConversion er)=20
  {=0A=
    // we still need to cache bad conversions incase something goes =0A=
    // wrong when the data is converted into stock=0A=
    cerr << "Error: Tried to convert \"" << er.data << "\" to a \""=0A=
	 << er.type_name << "\"." << endl;=0A=
    return -1;=0A=
  }
	cout << endl << endl << "Press any key to exit...";=09
	getchar();=0A=
	return 0;=0A=
}

void QueryDatabases()
{
	Connection con(def_db_name, def_host_name, def_user_name, =
def_password);
	Query query =3D con.query();
	query << "show databases";
=09
	cout << endl << "Query: " << query.preview() << endl;

	Result res =3D query.store();

	Row row;
	cout.setf(ios::left);
=20
	Result::iterator i;
	// The Result class has a read-only Random Access Iterator
	for (i =3D res.begin(); i !=3D res.end(); i++)=20
	{
		row =3D *i;
		cout <<setw(17) << row[0]=20
//			<< setw(4)  << row[1]=20
//			<< setw(7)  << row[2]
//			<< setw(7)  << row[3]
//			<< row[4]=20
			<< endl;		=09
	}
	cout << endl << "Records Found: " << res.size() << endl;
}

void ExecQuery(string sQuery)
{
	Connection con(def_db_name, def_host_name, def_user_name, =
def_password);
	Query query =3D con.query();
	// This creates a query object that is bound to con.

	query << sQuery;
	// You can write to the query object like you would any other ostrem	=09
	=09
	cout << endl << "Query: " << query.preview() << endl;
	// Show the query before it is executed
	// Query::preview() simply returns a string with the current query
	// string in it.
	=09
	Result res =3D query.store();

	// Query::store() executes the query and returns the results
=09
	Row row;
	cout.setf(ios::left);
//	cout << setw(17) << "Database Name" << endl << endl;
=20
	Result::iterator i;
=09
	for (i =3D res.begin(); i !=3D res.end(); i++)=20
	{
		row =3D *i;
		cout <<setw(17) << row[0]=20
			<< setw(4)  << row[1]=20
			<< setw(7)  << row[2]
			<< setw(7)  << row[3]
			<< row[4] << endl;		=09
	}
	cout << endl << "Records Found: " << res.size()  << endl;
}

------=_NextPart_000_000C_01C0FE87.67E20680
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
------=_NextPart_000_000C_01C0FE87.67E20680--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019