mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	sql console now shows error message if any SQL error ocurred
This commit is contained in:
		| @@ -20,15 +20,22 @@ const sqlConsole = (function() { | |||||||
|     async function execute() { |     async function execute() { | ||||||
|         const sqlQuery = queryEl.val(); |         const sqlQuery = queryEl.val(); | ||||||
|  |  | ||||||
|         const results = await server.post("sql/execute", { |         const result = await server.post("sql/execute", { | ||||||
|             query: sqlQuery |             query: sqlQuery | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|  |         if (!result.success) { | ||||||
|  |             showError(result.error); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         const rows = result.rows; | ||||||
|  |  | ||||||
|         resultHeadEl.empty(); |         resultHeadEl.empty(); | ||||||
|         resultBodyEl.empty(); |         resultBodyEl.empty(); | ||||||
|  |  | ||||||
|         if (results.length > 0) { |         if (rows.length > 0) { | ||||||
|             const result = results[0]; |             const result = rows[0]; | ||||||
|             const rowEl = $("<tr>"); |             const rowEl = $("<tr>"); | ||||||
|  |  | ||||||
|             for (const key in result) { |             for (const key in result) { | ||||||
| @@ -38,7 +45,7 @@ const sqlConsole = (function() { | |||||||
|             resultHeadEl.append(rowEl); |             resultHeadEl.append(rowEl); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         for (const result of results) { |         for (const result of rows) { | ||||||
|             const rowEl = $("<tr>"); |             const rowEl = $("<tr>"); | ||||||
|  |  | ||||||
|             for (const key in result) { |             for (const key in result) { | ||||||
|   | |||||||
| @@ -8,7 +8,18 @@ const sql = require('../../services/sql'); | |||||||
| router.post('/execute', auth.checkApiAuth, async (req, res, next) => { | router.post('/execute', auth.checkApiAuth, async (req, res, next) => { | ||||||
|     const query = req.body.query; |     const query = req.body.query; | ||||||
|  |  | ||||||
|     res.send(await sql.getResults(query)); |     try { | ||||||
|  |         res.send({ | ||||||
|  |             success: true, | ||||||
|  |             rows: await sql.getResults(query) | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  |     catch (e) { | ||||||
|  |         res.send({ | ||||||
|  |             success: false, | ||||||
|  |             error: e.message | ||||||
|  |         }); | ||||||
|  |     } | ||||||
| }); | }); | ||||||
|  |  | ||||||
| module.exports = router; | module.exports = router; | ||||||
| @@ -192,6 +192,8 @@ async function wrap(func) { | |||||||
|     catch (e) { |     catch (e) { | ||||||
|         log.error("Error executing query. Inner exception: " + e.stack + thisError.stack); |         log.error("Error executing query. Inner exception: " + e.stack + thisError.stack); | ||||||
|  |  | ||||||
|  |         thisError.message = e.stack; | ||||||
|  |  | ||||||
|         throw thisError; |         throw thisError; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user