<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Generische Datenbank Klasse]]></title><description><![CDATA[<p>Hmm, ich designe gerade eine generische Datenbank-Klasse für mein Projekt um darin gewisse Dinge wie Shader oder auch Scripts zu speichern und auch später komplexere Dinge.</p>
<p>Nun habe ich einige konzeptionelle Schwierigkeiten.<br />
Generell läuft das Erzeugen einer Datenbank so:</p>
<pre><code class="language-cpp">NLSqlite db;
	db.openDatabase(&quot;database/test.db&quot;);
	NLSQLTableDescriptor::TTableList lst;
	lst.push_back(NLSQLTableDescriptor(&quot;name&quot;, NLTT_TEXT|NLTT_UNIQUE|NLTT_PRIMARY));
	lst.push_back(NLSQLTableDescriptor(&quot;fragment&quot;, NLTT_TEXT));
	lst.push_back(NLSQLTableDescriptor(&quot;vertex&quot;, NLTT_TEXT));
	db.createTable(&quot;shader&quot;, lst);
</code></pre>
<p>In createTable werden die Parameter geprüft und dann entsprechend der SQL-String generiert.<br />
So weit ganz gut.<br />
Nun kommt aber das Problem bei einer Insert-Funktion.<br />
Bei Insert schaut der String so aus:</p>
<blockquote>
<p>INSERT INTO tablename(field1, field2, fieldn) VALUES(value1, value2, valuen);</p>
</blockquote>
<p>Jetzt brauche ich also eine Möglichkeit obiges um den Wert zu erweitern.<br />
Erst ist mir boost::any eingefallen. Aber halt, da sind ja noch die Blobs. boost::any kann mit reinen &quot;rohdaten&quot; (unsigned byte) denke ich nicht umgehen.<br />
Man könnte natürlich zur Klasse noch einen Zeiger auf ein u8 hinzufügen.<br />
Als Beispiel so:</p>
<pre><code class="language-cpp">class NLSQLTableDescriptor
{
public:
	typedef std::list&lt;NLSQLTableDescriptor&gt; TTableList;
public:
	/// \brief Constructor
	NLEXPORT NLSQLTableDescriptor() 
	{}

	/**
	 * \brief Constructor with options
	 * \param name The name of the field. 
	 * \param type The type of the field. 
	 * \see NLSQLFieldType for a description of the possible field-types.
	 */
	NLEXPORT NLSQLTableDescriptor(const std::string&amp; name, long type)
		: m_name(name), m_type(type), m_hasValue(false)
	{}

	/**
	 * \brief Constructor with options
	 * \param name The name of the field. 
	 * \param type The type of the field. 
	 * \param value The value for the entry.
	 * \see NLSQLFieldType for a description of the possible fields.
	 */
	NLEXPORT NLSQLTableDescriptor(const std::string&amp; name, boost::any value, long type)
		: m_name(name), m_type(type), m_value(value), m_hasValue(true)
	{}

	/// \brief Returns the name of the field. 
	NLEXPORT const std::string&amp; getName() const { return m_name; }

	/// \brief Returns the type of the field. 
	NLEXPORT const long getType() const { return m_type; }

	/// \brief Returns the value of the field.
	NLEXPORT const boost::any&amp; getValue() const { return m_value; }

	/// \brief Returns if the object was created with a value or not.
	NLEXPORT const bool hasValue() const { return m_hasValue; }

private:
	std::string m_name;
	long m_type;

	boost::any m_value;
	bool m_hasValue;
	u8* m_blob;
};
</code></pre>
<p>Ich hoffe man versteht was ich erreichen will. Das gleiche Problem trifft mich ja auch wieder, wenn ich Daten abhole aus der db.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/283413/generische-datenbank-klasse</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 15:24:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/283413.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 11 Mar 2011 11:43:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Generische Datenbank Klasse on Fri, 11 Mar 2011 11:43:39 GMT]]></title><description><![CDATA[<p>Hmm, ich designe gerade eine generische Datenbank-Klasse für mein Projekt um darin gewisse Dinge wie Shader oder auch Scripts zu speichern und auch später komplexere Dinge.</p>
<p>Nun habe ich einige konzeptionelle Schwierigkeiten.<br />
Generell läuft das Erzeugen einer Datenbank so:</p>
<pre><code class="language-cpp">NLSqlite db;
	db.openDatabase(&quot;database/test.db&quot;);
	NLSQLTableDescriptor::TTableList lst;
	lst.push_back(NLSQLTableDescriptor(&quot;name&quot;, NLTT_TEXT|NLTT_UNIQUE|NLTT_PRIMARY));
	lst.push_back(NLSQLTableDescriptor(&quot;fragment&quot;, NLTT_TEXT));
	lst.push_back(NLSQLTableDescriptor(&quot;vertex&quot;, NLTT_TEXT));
	db.createTable(&quot;shader&quot;, lst);
</code></pre>
<p>In createTable werden die Parameter geprüft und dann entsprechend der SQL-String generiert.<br />
So weit ganz gut.<br />
Nun kommt aber das Problem bei einer Insert-Funktion.<br />
Bei Insert schaut der String so aus:</p>
<blockquote>
<p>INSERT INTO tablename(field1, field2, fieldn) VALUES(value1, value2, valuen);</p>
</blockquote>
<p>Jetzt brauche ich also eine Möglichkeit obiges um den Wert zu erweitern.<br />
Erst ist mir boost::any eingefallen. Aber halt, da sind ja noch die Blobs. boost::any kann mit reinen &quot;rohdaten&quot; (unsigned byte) denke ich nicht umgehen.<br />
Man könnte natürlich zur Klasse noch einen Zeiger auf ein u8 hinzufügen.<br />
Als Beispiel so:</p>
<pre><code class="language-cpp">class NLSQLTableDescriptor
{
public:
	typedef std::list&lt;NLSQLTableDescriptor&gt; TTableList;
public:
	/// \brief Constructor
	NLEXPORT NLSQLTableDescriptor() 
	{}

	/**
	 * \brief Constructor with options
	 * \param name The name of the field. 
	 * \param type The type of the field. 
	 * \see NLSQLFieldType for a description of the possible field-types.
	 */
	NLEXPORT NLSQLTableDescriptor(const std::string&amp; name, long type)
		: m_name(name), m_type(type), m_hasValue(false)
	{}

	/**
	 * \brief Constructor with options
	 * \param name The name of the field. 
	 * \param type The type of the field. 
	 * \param value The value for the entry.
	 * \see NLSQLFieldType for a description of the possible fields.
	 */
	NLEXPORT NLSQLTableDescriptor(const std::string&amp; name, boost::any value, long type)
		: m_name(name), m_type(type), m_value(value), m_hasValue(true)
	{}

	/// \brief Returns the name of the field. 
	NLEXPORT const std::string&amp; getName() const { return m_name; }

	/// \brief Returns the type of the field. 
	NLEXPORT const long getType() const { return m_type; }

	/// \brief Returns the value of the field.
	NLEXPORT const boost::any&amp; getValue() const { return m_value; }

	/// \brief Returns if the object was created with a value or not.
	NLEXPORT const bool hasValue() const { return m_hasValue; }

private:
	std::string m_name;
	long m_type;

	boost::any m_value;
	bool m_hasValue;
	u8* m_blob;
};
</code></pre>
<p>Ich hoffe man versteht was ich erreichen will. Das gleiche Problem trifft mich ja auch wieder, wenn ich Daten abhole aus der db.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2032701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2032701</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Fri, 11 Mar 2011 11:43:39 GMT</pubDate></item><item><title><![CDATA[Reply to Generische Datenbank Klasse on Fri, 11 Mar 2011 21:34:03 GMT]]></title><description><![CDATA[<p>Hm, hast du eine konkrete Frage? Also geht es darum, wie sich die Blobs mit boost::any realisieren lassen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2032951</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2032951</guid><dc:creator><![CDATA[fdfdg]]></dc:creator><pubDate>Fri, 11 Mar 2011 21:34:03 GMT</pubDate></item></channel></rss>