No Kexi wrappers are built yet, but module and global scripts are
available to reports
Details
- Reviewers
staniek - Maniphest Tasks
- T4649: Add a new scripting module (JS)
- Commits
- R71:4adbe1bd36a4: WIP enable scripting in Kexi.
generate report with scripts
run 'executable' scripts within kexi. Scripts such as Kexi.openItem("report", "report_name"); works as expected
Example working script (providing database exists):
var db = new KDb(); console.log(db.driverNames()); var driver = db.driver("org.kde.kdb.sqlite"); console.log(driver.fileDBDriverMimeTypes()); var conn_data = db.createConnectionData(); conn_data.setDatabaseName("/home/piggz/Documents/Database/POI.kexi") var conn = driver.createConnection(conn_data); if (!conn.connect()) { console.log("Error connecting to database", conn.lastError()); } if (!conn.useDatabase("")) { console.log("Error using database", conn.lastError()); } console.log(conn.currentDatabase(), conn.isConnected()); console.log(conn.tableNames()); var cursor = conn.executeQueryString("select * from " + conn.tableNames()[0]); cursor.open(); var fieldcount = cursor.fieldCount(); while (!cursor.eof()) { for (var i = 0; i < fieldcount; ++i) { console.log(cursor.value(i)); } cursor.moveNext(); }
Diff Detail
- Repository
- R71 Kexi
- Branch
- kexi_scripting
- Lint
No Linters Available - Unit
No Unit Test Coverage
src/plugins/reports/kexireportpart.cpp | ||
---|---|---|
218 | if (win | |
src/plugins/scripting/kexidb/kexidbconnection.cpp | ||
27 ↗ | (On Diff #16671) | Can we set include paths and have just #include "kexiscriptingdebug.h" ? |
src/plugins/scripting/kexidb/kexidbfieldlist.cpp | ||
62 ↗ | (On Diff #15438) | Yep, massive change for all these const is OK. |
src/plugins/scripting/kexiscripting/kexiscriptdesignview.cpp | ||
391 | BTW | |
src/plugins/scripting/kexiscripting/kexiscriptpart.cpp | ||
100 | Better: xi18n("Error executing script at line %1:\n%2") | |
142 | I see. KexiPart::Part::loadSchemaObject() can be still useful if implemented, right? |
Looks nice, good job, some comments.
CMakeLists.txt | ||
---|---|---|
109 | instead how about: if(KEXI_SCRIPTS_SUPPORT) find_package(Qt5 5.8.0 COMPONENTS Qml) set_package_properties(Qt5Qml PROPERTIES DESCRIPTION "A framework for developing applications and libraries with the QML and JavaScript language." URL "http://qt.io" TYPE REQUIRED PURPOSE "Required by Kexi scripting (JavaScript)" ) endif() This way: KEXI_SCRIPTS_SUPPORT is fully controlled by the user, if right version of Qml is missing -> proper error with explanation why Qml is needed | |
src/plugins/scripting/kexidb/kexidbconnection.cpp | ||
89 ↗ | (On Diff #16760) | there's m_connection->options()->isReadOnly() |
182 ↗ | (On Diff #16760) | KDbConnection::CreateTableOption::Default not needed |
src/plugins/scripting/kexidb/kexidbdriver.cpp | ||
55 ↗ | (On Diff #16760) | m_driver->metaData()->mimeTypes()? |
src/plugins/scripting/kexidb/kexidbmodule.cpp | ||
91 ↗ | (On Diff #16760) | Remove const from return type |
93 ↗ | (On Diff #16760) | check is the list is not empty |
101 ↗ | (On Diff #16760) | probably QUrl::fromLocalFile is better if we assume local files, otherwise only true URLs will work |
117 ↗ | (On Diff #16760) | Like above |
src/plugins/scripting/kexidb/kexidbparser.h | ||
68 ↗ | (On Diff #16760) | missing const? Do we need it as slot? |
71 ↗ | (On Diff #16760) | Do we need it as slot? |
73 ↗ | (On Diff #16760) | Do we need it as slot? |
75 ↗ | (On Diff #16760) | Do we need it as slot? |
77 ↗ | (On Diff #16760) | missing const? Do we need it as slot? |
80 ↗ | (On Diff #16760) | missing const? Do we need it as slot? |
82 ↗ | (On Diff #16760) | missing const? Do we need it as slot? |
84 ↗ | (On Diff #16760) | missing const? Do we need it as slot? |
src/plugins/scripting/kexidb/kexidbschema.cpp | ||
133 ↗ | (On Diff #16760) | Not needed line? |
138 ↗ | (On Diff #16760) | QRegularExpression is the current API, can we use it? |
src/plugins/scripting/kexidb/kexidbschema.h | ||
67 ↗ | (On Diff #16760) | Do getters need to be slots? |
src/plugins/scripting/kexiscripting/kexiscriptdesignview.cpp | ||
391 | Sorry for confusion wrt disabling scripting. | |
src/plugins/scripting/kexiscripting/kexiscripteditor.cpp | ||
30 | not needed ; | |
46 | isEmpty() is safer | |
83 | KexiEditor::text() is already QString() |
src/plugins/scripting/kexidb/kexidbparser.h | ||
---|---|---|
84 ↗ | (On Diff #16760) | They dont need to be slots, but they do have to be Q_INVOKABLE to be accessible to the JS engine |
src/plugins/scripting/kexidb/kexidbschema.cpp | ||
138 ↗ | (On Diff #16760) | Ok, ive moved this to the new API, but I dont know if ive done it correct,y. Please check thoroughly. I suspect a test case would be good here! (infact, some test scripts to check the whole KDb wrapper would be very handy) |
Thanks for the update Adam.
Only one thing today. Unsure about the var db = new KDb(); construct (the meaning). There's in fact one KDb, having multiple KDbs won't bring multiple driver managers or or multiple SQLite drivers.
Regarding side question "what's the purpose of the operator new for us?", how about t = new Table(), t.addField(), ... , then conn.createTable(t)? And similar constructs.
Eventually 'r = new Report' then "setup design of r dynamically" then r.print(), then forget r. See the difference? r is not stored in the design, it's fully dynamic :)
Just quick thoughts to admit: expressiveness of the operator-new looks promising.
What is best, if you are happy with the engine port, do we push and work on the API separately? Do you want API changes for 3.1 or 4?
The patch for kexi is OFF by default (what marks it as experimental) so it's safe to have it in 3.1 after the review and officially marked as experimental. Then it can be all further developed in master.
Further rework would move db-related scripting code to KDb, leaving only Kexi-related part in kexi.git. Moving to KDb makes major changes to KDb so KDb version would be up to 4. Scripting does not need to be public API/feature of KDb anytime soon but it shall be there in KDb if we assume probability of accessing KDb internals.
- avoid conflict of macros KDE_DEFAULT_DEBUG_AREA
- Scripts have text mode only
- Missing include for kproperty master
src/plugins/CMakeLists.txt | ||
---|---|---|
1 | This line needs to be commented to avoid double definition (previous is in src/plugins/scripting/kexiscripting/CMakeLists.txt) | |
src/plugins/scripting/kexiscripting/kexi_scriptplugin.desktop | ||
56 | I am not sure Kexi/Viewer fits here. "Open" does not work. Only Kexi/Editor. By the way please change Kexi::DesignViewMode occurences to TextViewMode. | |
69–70 | Similarly, no Kexi/Viewer here |
Fixed all 3 my notes.
Now question, your test code probably works for me but I see no debug log in the output pane.
BTW I do not request changes to the javascript API. That would be different task after we get things designed.
- Enable the kexiadaptor object
- Enable KexiScriptAdaptor in the design view
- Start porting the kexidb module
- If it builds, relese it!
- Plug together the kdb wrappers
- Address comments
- Address comments
- Add KexiScriptingDebug
- No need to have an adaptor instance if they can be created at runtime
- Move execute from the view to the part
- Address comments
- Initialise
- Address comments
- Fixes
- Add stdout redirection to print JS output in the script designer
Almost there!
Big thanks Adam. Minor fixes proposed.
src/plugins/reports/kexireportpart.cpp | ||
---|---|---|
242 | -> qWarning | |
245 | -> qWarning | |
276 | -> qWarning | |
282 | -> qWarning | |
296 | -> qWarning | |
src/plugins/scripting/kexidb/kexidbconnection.cpp | ||
132 ↗ | (On Diff #17067) | -> KexiScriptingWarning, remove QString() |
144 ↗ | (On Diff #17067) | -> KexiScriptingWarning, remove QString() |
148 ↗ | (On Diff #17067) | -> KexiScriptingWarning, remove QString() |
src/plugins/scripting/kexidb/kexidbmodule.cpp | ||
135 ↗ | (On Diff #17067) | -> KexiScriptingWarning |
174 ↗ | (On Diff #17067) | -> KexiScriptingWarning |
src/plugins/scripting/kexiscripting/kexiscriptdesignview.cpp | ||
328 | -> KexiScriptingWarning | |
334 | -> KexiScriptingWarning | |
src/plugins/scripting/kexiscripting/kexiscriptingdebug.h | ||
1 ↗ | (On Diff #17067) | CamelCase recommended for new files --> KexiScriptingDebug.h |
27 ↗ | (On Diff #17067) | Add KexiScriptingWarning too |
src/plugins/scripting/kexiscripting/kexiscriptpart.cpp | ||
158 | -> KexiScriptingWarning | |
164 | -> KexiScriptingWarning |