Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » General » Downloads
 
Add your own
alternative version
Go to top

DarkSide SQL Mini Version 1, The embedded database

, 23 Mar 2006
An embedded database library in C++.
#include <iostream>
using namespace std;

#include "dsqlm.h"
using namespace dsqlm;

int main() {
  try {
    Database db("weather");	

	// create a table to store temperatures at different times of a day
	db.execute("create table temperatures(id autoid,rec_date date indexed,"
		"rec_time time,temp float)");
	char sql[101];
	float temp;
	while(true) {
		cout << "Enter temperature (0 to exit): ";
		cin >> temp;
		if(temp == 0) break;

		sprintf(sql,
			"insert into temperatures values(0,'sysdate','systime',%.2f)",
			temp);
		db.execute(sql);
		
		// find out todays average temperature
		ResultSet rslt = db.executeQuery("select temp,rec_time from temperatures where rec_date = 'sysdate'");		
		float tot = 0;
		int count = 0;
		cout << endl;
		while(rslt.next()) {
			cout << "Temp: "<<rslt.getString(1)<<"Recorded at: "
				<<rslt.getString(2)<<endl;
			tot += rslt.getFloat(1);
			count++;
		}
		cout << "Today's average temperature: " << (tot/count) << endl;
	}		
   }catch(DsqlMException ex) { 
     cout << ex.getMessage(); 
   } 
   return 1;
} 

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License

Share

About the Author

No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 23 Mar 2006
Article Copyright 2003 by AnOldGreenHorn
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid