get server version

This commit is contained in:
Jan Prochazka 2021-04-25 10:25:16 +02:00
parent 08692dc63f
commit 8ff706a17f
8 changed files with 88 additions and 2 deletions

View File

@ -17,6 +17,13 @@ module.exports = {
existing.structure = structure;
socket.emitChanged(`database-structure-changed-${conid}-${database}`);
},
handle_version(conid, database, { version }) {
const existing = this.opened.find(x => x.conid == conid && x.database == database);
if (!existing) return;
existing.serverVersion = version;
socket.emitChanged(`database-server-version-changed-${conid}-${database}`);
},
handle_error(conid, database, props) {
const { error } = props;
console.log(`Error in database connection ${conid}, database ${database}: ${error}`);
@ -51,6 +58,7 @@ module.exports = {
database,
subprocess,
structure: lastClosed ? lastClosed.structure : DatabaseAnalyser.createEmptyStructure(),
serverVersion: lastClosed ? lastClosed.serverVersion : null,
connection,
status: { name: 'pending' },
};
@ -175,6 +183,12 @@ module.exports = {
// };
},
serverVersion_meta: 'get',
async serverVersion({ conid, database }) {
const opened = await this.ensureOpened(conid, database);
return opened.serverVersion;
},
sqlPreview_meta: 'post',
async sqlPreview({ conid, database, objects, options }) {
// wait for structure

View File

@ -17,6 +17,12 @@ module.exports = {
existing.databases = databases;
socket.emitChanged(`database-list-changed-${conid}`);
},
handle_version(conid, { version }) {
const existing = this.opened.find(x => x.conid == conid);
if (!existing) return;
existing.version = version;
socket.emitChanged(`server-version-changed-${conid}`);
},
handle_status(conid, { status }) {
const existing = this.opened.find(x => x.conid == conid);
if (!existing) return;
@ -85,6 +91,12 @@ module.exports = {
return opened.databases;
},
version_meta: 'get',
async version({ conid }) {
const opened = await this.ensureOpened(conid);
return opened.version;
},
serverStatus_meta: 'get',
async serverStatus() {
return {

View File

@ -56,6 +56,12 @@ function setStatusName(name) {
setStatus({ name });
}
async function readVersion() {
const driver = requireEngineDriver(storedConnection);
const version = await driver.getVersion(systemConnection);
process.send({ msgtype: 'version', version });
}
async function handleConnect({ connection, structure }) {
storedConnection = connection;
lastPing = new Date().getTime();
@ -63,6 +69,7 @@ async function handleConnect({ connection, structure }) {
if (!structure) setStatusName('pending');
const driver = requireEngineDriver(storedConnection);
systemConnection = await checkedAsyncCall(connectUtility(driver, storedConnection));
readVersion();
if (structure) {
analysedStructure = structure;
handleIncrementalRefresh();

View File

@ -31,6 +31,12 @@ async function handleRefresh() {
}
}
async function readVersion() {
const driver = requireEngineDriver(storedConnection);
const version = await driver.getVersion(systemConnection);
process.send({ msgtype: 'version', version });
}
function setStatus(status) {
const statusString = stableStringify(status);
if (lastStatus != statusString) {
@ -51,6 +57,7 @@ async function handleConnect(connection) {
const driver = requireEngineDriver(storedConnection);
try {
systemConnection = await connectUtility(driver, storedConnection);
readVersion();
handleRefresh();
setInterval(handleRefresh, 30 * 1000);
} catch (err) {

View File

@ -4,6 +4,7 @@ export interface OpenedDatabaseConnection {
conid: string;
database: string;
structure: DatabaseInfo;
serverVersion?: any;
subprocess: ChildProcess;
disconnected?: boolean;
status?: {

View File

@ -14,7 +14,12 @@
import { extensions } from '../stores';
import stableStringify from 'json-stable-stringify';
import { useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
import {
useConnectionInfo,
useDatabaseInfo,
useDatabaseServerVersion,
useServerVersion,
} from '../utility/metadataLoaders';
import DataGrid from './DataGrid.svelte';
import ReferenceHeader from './ReferenceHeader.svelte';
@ -38,6 +43,9 @@
$: connection = useConnectionInfo({ conid });
$: dbinfo = useDatabaseInfo({ conid, database });
// $: serverVersion = useDatabaseServerVersion({ conid, database });
// $: console.log('serverVersion', $serverVersion);
let myLoadedTime = 0;

View File

@ -76,6 +76,18 @@ const databaseListLoader = ({ conid }) => ({
reloadTrigger: `database-list-changed-${conid}`,
});
const serverVersionLoader = ({ conid }) => ({
url: 'server-connections/version',
params: { conid },
reloadTrigger: `server-version-changed-${conid}`,
});
const databaseServerVersionLoader = ({ conid, database }) => ({
url: 'database-connections/server-version',
params: { conid, database },
reloadTrigger: `database-server-version-changed-${conid}-${database}`,
});
const archiveFoldersLoader = () => ({
url: 'archive/folders',
params: {},
@ -318,6 +330,21 @@ export function useDatabaseList(args) {
return useCore(databaseListLoader, args);
}
export function getServerVersion(args) {
return getCore(serverVersionLoader, args);
}
export function useServerVersion(args) {
return useCore(serverVersionLoader, args);
}
export function getDatabaseServerVersion(args) {
return getCore(databaseServerVersionLoader, args);
}
export function useDatabaseServerVersion(args) {
return useCore(databaseServerVersionLoader, args);
}
export function getServerStatus() {
return getCore(serverStatusLoader, {});
}

View File

@ -80,7 +80,17 @@ const driver = {
},
async getVersion(pool) {
const { version } = (await this.query(pool, 'SELECT @@VERSION AS version')).rows[0];
return { version };
const { productVersion } = (
await this.query(pool, "SELECT SERVERPROPERTY ('productversion') as productVersion")
).rows[0];
let productVersionNumber = 0;
if (productVersion) {
const splitted = productVersion.split('.');
const number = parseInt(splitted[0]) || 0;
productVersionNumber = number;
}
return { version, productVersion, productVersionNumber };
},
async listDatabases(pool) {
const { rows } = await this.query(pool, 'SELECT name FROM sys.databases order by name');