Skip to content

Commit 0681cf3

Browse files
committed
feat: plugin system — extract drivers into bundles with Settings UI
Extract all 8 database drivers into .tableplugin bundles loaded at runtime. Add Settings > Plugins tab for managing installed plugins.
1 parent ec30ce7 commit 0681cf3

247 files changed

Lines changed: 49618 additions & 251 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Plugins/ClickHouseDriverPlugin/ClickHousePlugin.swift

Lines changed: 696 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>TableProPluginKitVersion</key>
6+
<integer>1</integer>
7+
</dict>
8+
</plist>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// CFreeTDS.h
3+
// TablePro
4+
//
5+
// Umbrella header for FreeTDS db-lib C bridge.
6+
// Run scripts/build-freetds.sh to populate include/ with real FreeTDS headers.
7+
//
8+
9+
#include "include/sybfront.h"
10+
#include "include/sybdb.h"
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//
2+
// sybdb.h - FreeTDS db-lib stub header
3+
// Swift-compatible bridge: real libsybdb.a provides the implementation.
4+
//
5+
#ifndef _SYBDB_H_
6+
#define _SYBDB_H_
7+
8+
#include "sybfront.h"
9+
10+
// Opaque connection and login types.
11+
// Placeholder bodies allow Swift to use UnsafeMutablePointer<DBPROCESS>.
12+
// The real FreeTDS structs are internal; we never access fields from Swift.
13+
struct dbprocess { char _placeholder; };
14+
typedef struct dbprocess DBPROCESS;
15+
struct loginrec { char _placeholder; };
16+
typedef struct loginrec LOGINREC;
17+
18+
// Column type constants (TDS wire types)
19+
#define SYBCHAR 47
20+
#define SYBVARCHAR 39
21+
#define SYBNCHAR 175
22+
#define SYBNVARCHAR 103
23+
#define SYBTEXT 35
24+
#define SYBNTEXT 99
25+
#define SYBINT1 48
26+
#define SYBINT2 52
27+
#define SYBINT4 56
28+
#define SYBINT8 127
29+
#define SYBINTN 38
30+
#define SYBFLT8 62
31+
#define SYBREAL 59
32+
#define SYBFLTN 109
33+
#define SYBDECIMAL 106
34+
#define SYBNUMERIC 108
35+
#define SYBMONEY 60
36+
#define SYBMONEY4 122
37+
#define SYBMONEYN 110
38+
#define SYBBIT 50
39+
#define SYBBINARY 45
40+
#define SYBVARBINARY 37
41+
#define SYBIMAGE 34
42+
#define SYBDATETIME 61
43+
#define SYBDATETIME4 58
44+
#define SYBDATETIMN 111
45+
#define SYBUNIQUE 36
46+
47+
// Login property constants for dbsetlname() — values verified against FreeTDS 1.4 sybdb.h
48+
#define DBSETHOST 1
49+
#define DBSETUSER 2
50+
#define DBSETPWD 3
51+
#define DBSETAPP 5 // 4 is unused; real FreeTDS DBSETAPP = 5
52+
53+
// Convenience macros (match FreeTDS sybdb.h)
54+
#define DBSETLHOST(x, y) dbsetlname((x), (y), DBSETHOST)
55+
#define DBSETLUSER(x, y) dbsetlname((x), (y), DBSETUSER)
56+
#define DBSETLPWD(x, y) dbsetlname((x), (y), DBSETPWD)
57+
#define DBSETLAPP(x, y) dbsetlname((x), (y), DBSETAPP)
58+
59+
// TDS version constants — verified against FreeTDS 1.4 sybdb.h
60+
#define DBVERSION_74 8 // TDS 7.4 (SQL Server 2012+)
61+
62+
// Encryption
63+
#define ENCRYPT_OFF 0
64+
65+
// Error handler return codes
66+
#define INT_CANCEL 2
67+
#define INT_CONTINUE 1
68+
#define INT_EXIT 4
69+
70+
// Error handler function types
71+
typedef int (*EHANDLEFUNC)(DBPROCESS *dbproc, int severity, int dberr, int oserr,
72+
const char *dberrstr, const char *oserrstr);
73+
typedef int (*MHANDLEFUNC)(DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity,
74+
char *msgtext, char *srvname, char *proc, int line);
75+
76+
// Core db-lib API
77+
extern RETCODE dbinit(void);
78+
extern void dbexit(void);
79+
80+
extern LOGINREC *dblogin(void);
81+
extern void dbloginfree(LOGINREC *loginrec);
82+
extern RETCODE dbsetlname(LOGINREC *loginrec, const char *value, int which);
83+
extern RETCODE dbsetlversion(LOGINREC *loginrec, BYTE version);
84+
85+
// tdsdbopen is the real symbol; dbopen is a macro wrapper in the real header
86+
// (msdblib=1 enables MS SQL Server behavior — required for SQL Server connections)
87+
// Swift cannot expand C macros, so we expose a static inline function instead.
88+
extern DBPROCESS *tdsdbopen(LOGINREC *loginrec, const char *servername, int msdblib);
89+
static inline DBPROCESS *dbopen(LOGINREC *loginrec, const char *servername) {
90+
return tdsdbopen(loginrec, servername, 1);
91+
}
92+
extern RETCODE dbclose(DBPROCESS *dbproc);
93+
extern RETCODE dbuse(DBPROCESS *dbproc, const char *name);
94+
95+
extern RETCODE dbcmd(DBPROCESS *dbproc, const char *cmdstring);
96+
extern RETCODE dbsqlexec(DBPROCESS *dbproc);
97+
extern RETCODE dbresults(DBPROCESS *dbproc);
98+
extern RETCODE dbnextrow(DBPROCESS *dbproc);
99+
100+
extern int dbnumcols(DBPROCESS *dbproc);
101+
extern char *dbcolname(DBPROCESS *dbproc, int colnum);
102+
extern int dbcoltype(DBPROCESS *dbproc, int colnum);
103+
extern BYTE *dbdata(DBPROCESS *dbproc, int colnum);
104+
extern DBINT dbdatlen(DBPROCESS *dbproc, int colnum);
105+
106+
extern RETCODE dbcancel(DBPROCESS *dbproc);
107+
extern RETCODE dbcanquery(DBPROCESS *dbproc);
108+
109+
// Type conversion — converts a column value to a different TDS type (e.g. to SYBCHAR for display)
110+
extern DBINT dbconvert(DBPROCESS *dbproc, int srctype, const BYTE *src, DBINT srclen,
111+
int desttype, BYTE *dest, DBINT destlen);
112+
113+
extern EHANDLEFUNC dberrhandle(EHANDLEFUNC handler);
114+
extern MHANDLEFUNC dbmsghandle(MHANDLEFUNC handler);
115+
116+
extern char *dbversion(void);
117+
118+
#endif /* _SYBDB_H_ */
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// sybfront.h - FreeTDS sybfront stub header
3+
// Minimal types needed by sybdb.h
4+
//
5+
#ifndef _SYBFRONT_H_
6+
#define _SYBFRONT_H_
7+
8+
#include <stdint.h>
9+
10+
typedef unsigned char BYTE;
11+
typedef int32_t DBINT;
12+
typedef unsigned char DBBOOL;
13+
14+
#define SUCCEED 1
15+
#define FAIL 0
16+
17+
#define NO_MORE_RESULTS 2
18+
#define NO_MORE_ROWS -2
19+
20+
typedef int RETCODE;
21+
22+
#endif /* _SYBFRONT_H_ */
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module CFreeTDS {
2+
umbrella header "CFreeTDS.h"
3+
export *
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>TableProPluginKitVersion</key>
6+
<integer>1</integer>
7+
</dict>
8+
</plist>

0 commit comments

Comments
 (0)