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

PostgreSQL/libpqxx Class Generator

, 18 Aug 2006
Automated generation of PostgreSQL data transfer classes.
#pragma once

/***************************************************************************
 TableInfo.h  -  Contains class definitions for ColumnInfo and TableInfo.
                 These are in the one file because it didn't seem to make
				 sense to separate them.

 begin     : December 2004
 copyright : (C) 2004-2006 by Phil Cairns
 email     : oti169@hotmail.com
 $Id: TableInfo.h 2080 2006-08-18 01:53:19Z phil $

 This code may be used in compiled form in any way you desire (including
 commercial use). The code may be redistributed unmodified by any means
 providing it is not sold for profit without the authors written consent,
 and providing that this notice and the authors name and all copyright
 notices remains intact.

 This software is provided "as is" without express or implied warranty. Use
 it at your own risk!
 ***************************************************************************/

// A ColumnInfo object contains a definition for a column.
// These are stored in a COLUMNMAP, keyed on database
// column name.
struct ColumnInfo
{
	ColumnInfo() : isIndex(false) {}

	static std::string guessMemberType(const char* sz)
	{
		std::string ret;
		if ((0 == strncmp(sz, "int", 3) && isdigit(sz[3]))
			|| 0 == strcmp(sz, "oid"))
		{
			ret = "int";
		}
		else if (0 == strcmp(sz, "bool"))
		{
			ret = "bool";
		}
		else if (0 == strncmp(sz, "float", 5)
			|| 0 == strncmp(sz, "numeric", 7))
		{
			ret = "double";
		}
		else if (0 == strcmp(sz, "date")
			|| 0 == strcmp(sz, "time")
			|| 0 == strcmp(sz, "timestamp"))
		{
			ret = "COleDateTime";
		}
		else
		{
			ret = "std::string";
		}
		return ret;
	}
	std::string colPGType;
	std::string memberName;
	std::string memberType;
	bool isIndex;
	bool generate;
};
typedef std::map<std::string, ColumnInfo> COLUMNMAP;

// TableInfo contains the name of the file into which the
// class definition for the table will be put, the name the
// new class will have, and column map. These are stored in
// a TABLEINFOMAP, keyed on the database table name.
struct TableInfo
{
	TableInfo() {}
	TableInfo(const std::string& cName, const std::string& fName, const std::string& bName)
		: fileName(fName)
		, baseClass(bName)
		, className(cName)
		, generate(true)
	{
	}

	std::string fileName;
	std::string baseClass;
	std::string className;
	bool generate;
	COLUMNMAP columns;
};

typedef std::map<std::string, TableInfo> TABLEINFOMAP;

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

_oti

Australia Australia
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 18 Aug 2006
Article Copyright 2005 by _oti
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid