<commit_before>/*
 * FUNCTION:
 * sniff test.
 *
 * HISTORY:
 * Copyright (c) 2008 <NAME> <<EMAIL>>
 */

#include "odbcxx.h"

#include "Atom.h"

class AtomStorage
{
	private:
		ODBCConnection *db_conn;
		ODBCRecordSet *rs;
		bool column_cb(const char *colname, const char * colvalue)
		{
			printf ("%s = %s\n", colname, colvalue);
			return false;
		}
		bool row_cb(void)
		{
			printf ("---- New row found ----\n");
			rs->foreach_column(&AtomStorage::column_cb, this);
			return false;
		}
	public:
		AtomStorage(void);
		~AtomStorage();

		void storeAtom(Atom *);
		Atom * getAtom(Handle);
};

#include "Node.h"
#include "TLB.h"
#include "type_codes.h"

AtomStorage::AtomStorage(void)
{
	db_conn = new ODBCConnection("opencog", "linas", NULL);
}

AtomStorage::~AtomStorage()
{
	delete db_conn;
}

void AtomStorage::storeAtom(Atom *atom)
{
	std::string cols = "INSERT INTO Atoms (";
	std::string vals = ") VALUES (";

	char buff[24];
	Handle h = TLB::getHandle(atom);
	snprintf(buff, 24, "%lu", (unsigned long) h);
	cols += "uuid"; 
	vals += buff;

	Type t = atom->getType();
	snprintf(buff, 24, "%u", t);
	cols += ", type"; 
	vals += ", "; 
	vals += buff;

	Node *n = dynamic_cast<Node *>(atom);
	if (n)
	{
		cols += ", name";
		vals += ", '";
		vals += n->getName();
		vals += "'";
	}

	std::string qry = cols + vals + ");";
printf ("duude its %s\n", qry.c_str());
	db_conn->exec(qry.c_str());
}

Atom * AtomStorage::getAtom(Handle h)
{
	rs = db_conn->exec("SELECT * FROM Atoms;");
	rs->foreach_row(&AtomStorage::row_cb, this);
	rs->release();
	return NULL;
}

int main ()
{
	AtomStorage *store = new AtomStorage();

	Atom *a = new Node(SCHEMA_NODE, "someNode");
printf ("hello\n");

	store->storeAtom(a);
	store->getAtom(a);


	return 0;
}

/* ============================= END OF FILE ================= */<commit_msg>more hacking<commit_after>/*
 * FUNCTION:
 * sniff test.
 *
 * HISTORY:
 * Copyright (c) 2008 <NAME> <<EMAIL>>
 */

#include "odbcxx.h"

#include "Atom.h"

class AtomStorage
{
	private:
		ODBCConnection *db_conn;
		ODBCRecordSet *rs;
		bool column_cb(const char *colname, const char * colvalue)
		{
			printf ("%s = %s\n", colname, colvalue);
			return false;
		}
		bool row_cb(void)
		{
			printf ("---- New row found ----\n");
			rs->foreach_column(&AtomStorage::column_cb, this);
			return false;
		}

		bool row_exists;
		bool row_exists_cb(void)
		{
			row_exists = true;
			return false;
		}

	public:
		AtomStorage(void);
		~AtomStorage();

		void storeAtom(Atom *);
		bool atomExists(Handle);
		Atom * getAtom(Handle);
};

#include "Node.h"
#include "TLB.h"
#include "type_codes.h"

AtomStorage::AtomStorage(void)
{
	db_conn = new ODBCConnection("opencog", "linas", NULL);
}

AtomStorage::~AtomStorage()
{
	delete db_conn;
}

#define BUFSZ 34

#define STMT(colname,val) { \
	if(update) { \
	} else { \
		if (notfirst) { cols += ", "; vals += ", "; } else notfirst = 1; \
		cols += colname; \
		vals += val; \
	} \
}

void AtomStorage::storeAtom(Atom *atom)
{
	int notfirst = 0;
	std::string cols;
	std::string vals;
	std::string coda;

	Handle h = TLB::getHandle(atom);

	// Currently using the TLB Handle as the UUID, ...XXX
	char uuidbuff[BUFSZ];
	snprintf(uuidbuff, BUFSZ, "%lu", (unsigned long) h);

	bool update = atomExists(h);
	if (update)
	{
printf ("duude atom exists\n");
		cols = "UPDATE Atoms SET ";
		coda = "WHERE uuid = ";
		coda += uuidbuff;
		coda += ";";
	}
	else
	{
		cols = "INSERT INTO Atoms (";
		vals = ") VALUES (";
		coda = ");";
	}

	STMT("uuid", uuidbuff);

	char buff[BUFSZ];
	Type t = atom->getType();
	snprintf(buff, BUFSZ, "%u", t);
	STMT("type", buff);

	Node *n = dynamic_cast<Node *>(atom);
	if (n)
	{
		std::string qname = "'";
		qname += n->getName();
		qname += "'";
		STMT("name", qname);
	}

	std::string qry = cols + vals + coda;
printf ("duude its %s\n", qry.c_str());
	db_conn->exec(qry.c_str());
}

/**
 * Return true if the indicated handle esists in the storage.
 */
bool AtomStorage::atomExists(Handle h)
{
	char buff[BUFSZ];
	snprintf(buff, BUFSZ, "%lu", (unsigned long) h);

	std::string select = "SELECT uuid FROM Atoms WHERE uuid = ";
	select += buff;
	select += ";"; 
	rs = db_conn->exec(select.c_str());

	row_exists = false;
	rs->foreach_row(&AtomStorage::row_exists_cb, this);
	rs->release();
	return row_exists;
}

Atom * AtomStorage::getAtom(Handle h)
{
	char buff[BUFSZ];
	snprintf(buff, BUFSZ, "%lu", (unsigned long) h);

	std::string select = "SELECT * FROM Atoms WHERE uuid = ";
	select += buff;
	select += ";"; 
	rs = db_conn->exec(select.c_str());
	rs->foreach_row(&AtomStorage::row_cb, this);
	rs->release();
	return NULL;
}

int main ()
{
	AtomStorage *store = new AtomStorage();

	Atom *a = new Node(SCHEMA_NODE, "someNode");
printf ("hello\n");

	store->storeAtom(a);

	Handle h = TLB::getHandle(a);
	store->getAtom(h);


	return 0;
}

/* ============================= END OF FILE ================= */
{'fraction_non_alphanumeric': 0.20473566033884466, 'fraction_numerical': 0.004082465809348847, 'mean_word_length': 3.865938430983118, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1638754', 'n_tokens_mistral': 2055, 'n_tokens_neox': 1934, 'n_words': 445}