return exec(q);
}
+int Database::getNextUdpClientId()
+{
+ QSqlQuery &q = prepare("SELECT nextval('udp_client_session')");
+
+ if (!exec(q))
+ return 0;
+
+ if (!q.next())
+ return 0;
+
+ int ret = q.value(0).toInt();
+
+ q.finish();
+
+ return ret;
+}
+
QSqlDatabase Database::connection() const
{
return d->db;
bool log(const QString &message, int type = 1);
+ int getNextUdpClientId();
+
QSqlDatabase connection() const;
QSqlQuery &prepare(const char *const sql);
db = new Database("main");
connect(db, SIGNAL(connected()), this, SLOT(setupHostInfo()));
m_settings = new Settings(db, this);
+
+ m_udpClientId = 0;
}
MyList::~MyList()
return tasks.count();
}
+int MyList::udpClientId() const
+{
+ return m_udpClientId;
+}
+
QSettings *MyList::defaultLocalQSettings() const
{
return m_defaultLocalQSettings;
if (!db->isConnected())
return;
+ if (!isUdpHost())
+ return;
+
+ m_udpClientId = database()->getNextUdpClientId();
+
+ Q_ASSERT_X(m_udpClientId, "MyList", "Failed to get UDP Client Id");
+
using namespace ::AniDBUdpClient;
Client::instance()->setHost(m_settings->get("udpClientHost").toString());
Client::instance()->setHostPort(m_settings->get("udpClientHostPort").toUInt());
class RenameHandler;
class DirectoryWatcher;
-class LOCALMYLISTSHARED_EXPORT MyList : public QObject {
+class LOCALMYLISTSHARED_EXPORT MyList : public QObject
+{
Q_OBJECT
Q_PROPERTY(LocalMyList::Database *database READ database)
Q_PROPERTY(LocalMyList::Settings *settings READ settings)
Q_PROPERTY(int hostId READ hostId)
Q_PROPERTY(bool isUdpHost READ isUdpHost)
Q_PROPERTY(int runningTaskCount READ runningTaskCount)
+ Q_PROPERTY(int udpClientId READ udpClientId)
public:
MyList();
int runningTaskCount();
+ int udpClientId() const;
+
QSettings *defaultLocalQSettings() const;
public slots:
QSettings *m_defaultLocalQSettings;
+ int m_udpClientId;
+
public:
static MyList *instance();
static void destroy();
-- Delete rules
CREATE OR REPLACE RULE file_location_delete_notify_rule AS
ON DELETE TO file_location DO SELECT pg_notify('file_location_delete', old.location_id::text || ',' || old.fid::text);
+
+
+-- Sequences
+CREATE SEQUENCE udp_client_session;