示例#1
0
static void daemon_data_sqlite_data_real_Init (DaemonDataIDataAccess* base, const gchar* logPath, GError** error) {
	DaemonDataSqliteData * self;
	gchar* _tmp0_;
	gchar* _tmp1_;
	sqlite3* _tmp3_ = NULL;
	gint _tmp4_;
	gint _result_;
	GError * _inner_error_ = NULL;
	self = (DaemonDataSqliteData*) base;
	_tmp0_ = g_strdup (logPath);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == NULL) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup ("data.db");
		_g_free0 (_tmp1_);
		_tmp1_ = _tmp2_;
	}
	_tmp4_ = sqlite3_open (_tmp1_, &_tmp3_);
	_sqlite3_close0 (self->priv->_database);
	self->priv->_database = _tmp3_;
	_result_ = _tmp4_;
	if (_result_ != SQLITE_OK) {
		GError* _tmp5_ = NULL;
		_tmp5_ = g_error_new_literal (DAEMON_DATA_DATA_ACCESS_ERROR, DAEMON_DATA_DATA_ACCESS_ERROR_OpenFailed, "Could not open Database");
		_inner_error_ = _tmp5_;
		if (_inner_error_->domain == DAEMON_DATA_DATA_ACCESS_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_free0 (_tmp1_);
			return;
		} else {
			_g_free0 (_tmp1_);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	daemon_data_sqlite_data_CreateSchema (self, &_inner_error_);
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == DAEMON_DATA_DATA_ACCESS_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_free0 (_tmp1_);
			return;
		} else {
			_g_free0 (_tmp1_);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	_g_free0 (_tmp1_);
}
示例#2
0
static void daemon_data_sqlite_data_finalize (GObject* obj) {
	DaemonDataSqliteData * self;
	self = DAEMON_DATA_SQLITE_DATA (obj);
	_sqlite3_close0 (self->priv->_database);
	G_OBJECT_CLASS (daemon_data_sqlite_data_parent_class)->finalize (obj);
}
示例#3
0
void irc_sq_lite_db_ShowLog (const char* username) {
	sqlite3* _tmp0_ = NULL;
	sqlite3* _tmp1_;
	char* commandText;
	sqlite3_stmt* statement;
	sqlite3_stmt* _tmp2_ = NULL;
	sqlite3_stmt* _tmp3_;
	gint _result_;
	GList* results;
	g_return_if_fail (username != NULL);
	fprintf (stdout, "Datenbank wird ausgelesen!\n");
	sqlite3_open (IRC_SQ_LITE_DB__path, &_tmp0_);
	irc_sq_lite_db_DataBase = (_tmp1_ = _tmp0_, _sqlite3_close0 (irc_sq_lite_db_DataBase), _tmp1_);
	commandText = g_strdup ("SELECT * FROM MyLogData WHERE Username = @1 ORDER BY Timestamp DESC LI" \
"MIT 10");
	statement = NULL;
	sqlite3_prepare_v2 (irc_sq_lite_db_DataBase, commandText, -1, &_tmp2_, NULL);
	statement = (_tmp3_ = _tmp2_, _sqlite3_finalize0 (statement), _tmp3_);
	sqlite3_bind_text (statement, 1, g_strdup (username), -1, g_free);
	_result_ = sqlite3_step (statement);
	results = NULL;
	while (TRUE) {
		char* Username;
		char* MessageContent;
		char* Channel;
		char* Server;
		GDateTime* FromUnixTime;
		IRCMessage* msg;
		if (!(_result_ == SQLITE_ROW)) {
			break;
		}
		Username = g_strdup (sqlite3_column_text (statement, 0));
		MessageContent = g_strdup (sqlite3_column_text (statement, 1));
		Channel = g_strdup (sqlite3_column_text (statement, 2));
		Server = g_strdup (sqlite3_column_text (statement, 3));
		FromUnixTime = g_date_time_new_from_unix_local (g_ascii_strtoll (sqlite3_column_text (statement, 4), NULL, 0));
		msg = irc_message_new (Username, MessageContent, Channel, Server, FromUnixTime);
		results = g_list_append (results, _irc_message_ref0 (msg));
		_result_ = sqlite3_step (statement);
		_irc_message_unref0 (msg);
		_g_date_time_unref0 (FromUnixTime);
		_g_free0 (Server);
		_g_free0 (Channel);
		_g_free0 (MessageContent);
		_g_free0 (Username);
	}
	{
		GList* r_collection;
		GList* r_it;
		r_collection = results;
		for (r_it = r_collection; r_it != NULL; r_it = r_it->next) {
			IRCMessage* r;
			r = _irc_message_ref0 ((IRCMessage*) r_it->data);
			{
				fprintf (stdout, "%s\n", irc_message_get_MessageContent (r));
				_irc_message_unref0 (r);
			}
		}
	}
	__g_list_free_irc_message_unref0 (results);
	_sqlite3_finalize0 (statement);
	_g_free0 (commandText);
}
示例#4
0
void irc_sq_lite_db_CreateDB (void) {
	sqlite3* _tmp0_ = NULL;
	gint _tmp1_;
	sqlite3* _tmp2_;
	gint _result_;
	char* createLog;
	_result_ = (_tmp1_ = sqlite3_open (IRC_SQ_LITE_DB__path, &_tmp0_), irc_sq_lite_db_DataBase = (_tmp2_ = _tmp0_, _sqlite3_close0 (irc_sq_lite_db_DataBase), _tmp2_), _tmp1_);
	createLog = g_strdup ("CREATE TABLE MyLogData (Username TEXT, Message TEXT NULL, Channel TEXT" \
", Server TEXT, Timestamp INTEGER)");
	if (_result_ == SQLITE_OK) {
		_sqlite3_exec (irc_sq_lite_db_DataBase, createLog, NULL, NULL, NULL);
	}
	_g_free0 (createLog);
}