Click here to Skip to main content
15,886,518 members
Articles / Database Development / SQL Server

DarkSide SQL Mini Version 1, The embedded database

Rate me:
Please Sign up or sign in to vote.
3.50/5 (27 votes)
23 Mar 2006BSD2 min read 157K   2.9K   57  
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


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions