Files
l7/L7/LPQConnection.h
SET aaacf88071 Added classes to manage simple tabular data of known structure using a
popup containing a wxGrid object.

BasePicker : Abstract class adding a popup to wxPickerBase  styled with
a wxTextCtrl.
BaseGridPicker : Abstract class adding a wxGrid in the popup.

JsonGridPickerCtrl : UI control storing the tabular data in a JSON
array.
LBoundJsonGridPicker : connect JsonGridPicker to database.
LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects.
LGridJsonCellRenderer : render cell JSON data.

XmlGridPickerCtrl : UI control storing the tabular data in as XML
document.
LBoundXmlGridPicker : connect XmlGridPicker to database.
LGridXmlCellEditor : grid editor for LBoundXmlGridPicker.
LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker.

JsonHelper and XmlHelper : for applications to quickly get intent value
from database data..

The structure of managed tabular data :

Column 1 : Intent - this is what we want to store/edit. This can be
telephone numbers, email addresses, instant messaging addresses...
any single line piece of information that can exist many times for one
entity (person, company...).
Column 2 : Type - A short description of the intent : 'Home, Work,
Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox.
Column 3 : Preferred - One line of data can be selected as the preferred
one. It is not mandatory, but it must be a single choice.
Column 4 : Notes - single line notes.

Adjust sql scripts and L7.dox.
Applied ANSI formatting style to all files.

Other changes :

Work around a nasty misbehavior.
Grid columns edited by a translated combobox expect full string
data as cell values. LResultSet::BEData() will report these mapped strings,
instead of database real data. LBoundComboBox::IsDirty() will always be
true even if the editor is unchanged once created.
Simplest workaround : disconnect m_BoundComboBox if unchanged.

LGridTextEditor::ProvideFormEditor() : set the form editor's value
explicitely.; wxTextCtrl does not interpret data it receives

LBoundControl::SetNull must be void.

LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind::

LConnection::GetReturnedKeys should return NULL.
LConnection::SetData should return void.

Notes : wxJSON must be configured with the same prefix as wxWidgets,
here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-23 08:12:01 +01:00

135 lines
4.0 KiB
C++

/*
* File: LPQConnection.h
* Author: SET - nmset@netcourrier.com
* License : LGPL version 2.1
* Copyright SET, M. D. - © 2014
*
* Created on 25 mai 2014, 11:43
*/
#ifdef USE_LIBPQ
#ifndef LPQCONNECTION_H
#define LPQCONNECTION_H
#include <wx/wx.h>
#include <libpq-fe.h>
#include "LConnection.h"
/**
* PostgreSQL namespace.
*
* Please note USE_LIBPQ pre-processor directive must be defined to include the PostgreSQL backend.
*/
namespace PQ
{
#define CNPQMC wxString(_T("CNPQM"))
/**
Minimalist class managing a PostgreSQL connection.
*/
class LPQConnection : public LConnection
{
public:
LPQConnection();
/**
* Ex : host=localhost port=5432 dbname=postgres user=postgres password=secret
* @param newInfo connection information.
*/
LPQConnection(const wxString& newInfo);
/**
* The connection is closed in the destructor. Clears any returned keys.
* But any fetched resultset persists. The caller is responsible to clear this.
*/
virtual ~LPQConnection();
/**
*
* @return the last backend error message, may be NULL.
*/
const char* GetLastLibMessage() const;
/**
* Establishes a new connection calling PQconnectdb
*
* Does nothing if a connection already exists.
* Updates the username, dbname, servername and port variables.
* @return true if a new connection is established, or if a connection already esists. False on error.
*/
bool Connect();
/**
*
* @return a pointer to the PGconn real database pointer.
*/
void* Get() const;
/**
* Evaluates PQstatus(PGconn*).
* @return true if the database connection is valid, false otherwise.
*/
bool IsValid() const;
/**
* Closes the connection.
*
* The data referenced in a PGresult object is not cleared.
* It is the responsibility of the caller to free this object.
*/
void Close();
/**
* Performs synchronous PQexec query and returns rows from a SELECT query.
*
* @param newSql : a valid single SELECT SQL statement.
* @return an untyped pointer to a PGresult containing the data, or NULL on error.
*/
void* ExecuteSQL(const wxString& newSql);
/**
* Intended for database actions that do not fetch table rows. Performs synchronous PQexec query.
*
* @param newSql a valid single SQL statement.
* @return true on success, false otherwise.
*/
bool ExecuteUpdateSQL(const wxString& newSql);
/**
* The value of an auto-generated primary key after executing an INSERT SQL statement.
*
* The SQL statement should have a RETURNING clause that includes a serial column, whose
* index is specified by the col parameter. The column value of the first row is returned.
* @param col index of an auto-increment serial column in a RETURNING SQL clause.
* @return the value of the first row for that column.
*/
const wxAny GetReturnedValue(const unsigned int col) const;
/**
* PGresult object containing a primary key value
* resulting from a successful execution of an INSERT SQL statement.
* @return an untyped pointer to the PGresult object containing the key.
*/
void* GetReturnedKeys() const;
/**
* Clears the PGresult object to free memory.
*/
void ClearReturnedKeys();
private:
PGconn * m_conn;
PGresult * m_retKeys;
bool ApplyReadWriteStatus();
/**
* Forwards libpq messages to InformLibMessage
* @param
*/
void InformPQMessage(const char * PQmsg) const;
/**
* Informs application an SQL statement is about to be processed regardless of connection status..
*/
void InformBeforeExecute();
/**
* Informs application an SQL statement has been processed, regardless of errors.
*/
void InformAfterExecute();
/**
* Informs application that registers LConnectionEvent handlers here.
* @param msg
*/
void InformLibMessage(const LInformation& msg) const;
};
}
#endif /* LPQCONNECTION_H */
#endif