Enable KREPORT_SCRIPTING in reports and switch to updated api
ClosedPublic

Authored by staniek on Aug 13 2015, 3:29 PM.

Diff Detail

Repository
R8 Calligra
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
piggz updated this revision to Diff 549.Aug 13 2015, 3:29 PM
piggz retitled this revision from to Enable KREPORT_SCRIPTING in reports and switch to updated api.
piggz updated this object.
piggz edited the test plan for this revision. (Show Details)
piggz added a reviewer: staniek.
staniek requested changes to this revision.Aug 13 2015, 3:55 PM
staniek edited edge metadata.

Cool, minor notes.

I think we can remove use of ifdef KREPORT_SCRIPTING from Kexi.
Instead we can add a cmake-level check to ensure KREPORT_SCRIPTING is ON.
So if missing, it won't look like a bug in Kexi code.

Further task would be create an abstract interface for KRScriptFunctions in KReport and make KRScriptFunctions in Kexi implementing it. KReport's example can implement it in a limited way. Interested?

Later, the KRScriptFunctions' implementation could be part of a KReport-KDb lib.

kexi/plugins/reports/kexidbreportdata.cpp
318–320

-> 0 == QString::compare(QString, Qt::CaseInsensitive)

370–372

-> 0 == QString::compare(QString, Qt::CaseInsensitive)

kexi/plugins/reports/kexireportview.cpp
33–34

like above

168–169

like above

401–404

like above

kexi/plugins/reports/kexireportview.h
36

For all commented code let's use:
//! @todo KEXI3

so we either remove or port it later

76

like above

kexi/plugins/reports/krscriptfunctions.cpp
54

How about using m_connection->querySingleString(KDbQuerySchema* query, QString* value)?
Safer (no risk of SQL injection) and simpler.

This revision now requires changes to proceed.Aug 13 2015, 3:55 PM
piggz updated this revision to Diff 552.Aug 15 2015, 11:40 AM
piggz edited edge metadata.
piggz marked 7 inline comments as done.
  • Address comments round 1
piggz marked an inline comment as done.Aug 15 2015, 12:00 PM
piggz added inline comments.
kexi/plugins/reports/krscriptfunctions.cpp
54

Done, but used querySingString(KDbEscapedString......)

piggz marked an inline comment as done.Aug 15 2015, 12:01 PM

I'll tackle the abstract interface for functions next.

piggz updated this revision to Diff 557.Aug 16 2015, 6:35 PM
piggz edited edge metadata.
  • Implement the new kreport group tracker api
staniek requested changes to this revision.Aug 23 2015, 8:34 AM
staniek added a project: Kexi: Porting to Qt 5.
staniek edited edge metadata.

More comments...

kexi/plugins/CMakeLists.txt
2 ↗(On Diff #557)
kexi/plugins/reports/kexidbreportdata.cpp
318–320

Missing 2x "0 =="

370–372

Again, missing 2x "0 =="

370–372

Plus, it would make sense to have an internal (not exported) function and use it

static bool isInterpreterSupported(const QString &interpreterName)
kexi/plugins/reports/kexidbreportdata.h
70

Consistency: script -> scriptname

kexi/plugins/reports/kexireportview.h
76

!todo -> ! @todo

(in 3 places)

kexi/plugins/reports/krscriptfunctions.cpp
48–53

No need to initialize, QString().toReal() returns 0.0 too.

54
  1. Let's use KDb::escapeIdentifier(field).
  1. Still, 'function' is unsafe (SQL injection possible) and we have no escaping for it until we employ a function parser here.

So how about adding a backlog here:

//! @todo KEXI3 'function' is unsafe (SQL injection possible), we have no escaping for it, employ a function parser here
57

"WHERE(" -> "WHERE ("

62

space after ,

64

OK, just we have no error reporting e.g. for sqrt(-1.0), maybe add a todo?

116

*i -> it
*let's use KDb::escapeIdentifier(it.key())
*let's use KDb::escapeString(it.value().toString())

kexi/plugins/reports/krscriptfunctions.h
50

Let's make it const

This revision now requires changes to proceed.Aug 23 2015, 8:34 AM
staniek added inline comments.Aug 23 2015, 8:37 AM
kexi/plugins/reports/krscriptfunctions.h
29

Where's the file?

staniek added inline comments.Aug 23 2015, 1:16 PM
kexi/plugins/CMakeLists.txt
2 ↗(On Diff #557)

Update:
Changes in this file not needed at all.
Please update KReport master (see https://quickgit.kde.org/?p=kreport.git&a=commit&h=50d5b15c1b66c49af2ff451283e29e1f243e4e61) and calligra.git kexi-frameworks8-staniek (https://quickgit.kde.org/?p=calligra.git&a=commit&h=9ff99ad767a0c44cd8be99fa0b465f2da97a4808)

BTW, This report (see the XML below) crashes for me on preview:

<!DOCTYPE kexireport>
<kexireport>
 <report:content xmlns:report="http://kexi-project.org/report/2.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0">
  <report:title>Report</report:title>
  <report:script report:script-interpreter="javascript"></report:script>
  <report:grid report:grid-divisions="4" report:grid-snap="1" report:page-unit="cm" report:grid-visible="1"/>
  <report:page-style report:print-orientation="portrait" fo:margin-bottom="28.346505799999999pt" fo:margin-top="28.346505799999999pt" fo:margin-left="28.346505799999999pt" fo:margin-right="28.346505799999999pt" report:page-size="A4">predefined</report:page-style>
  <report:body>
   <report:detail>
    <report:section svg:height="77.952890950006235pt" fo:background-color="#ffffff" report:section-type="detail">
     <report:field report:item-data-source="=field.value(&quot;date&quot;)+&quot;\n&quot;+field.value(&quot;uptime&quot;)+&quot;\n&quot;+field.value(&quot;dns&quot;)+&quot;\n&quot;+field.value(&quot;connect&quot;)" report:name="field2" report:word-wrap="0" report:can-grow="1" report:horizontal-align="left" svg:x="7.086626450000000pt" svg:width="531.496983750085064pt" svg:y="7.086626450000000pt" report:vertical-align="center" svg:height="14.173252900002270pt" report:z-index="0">
      <report:text-style fo:letter-spacing="0%" style:letter-kerning="true" fo:font-size="11" fo:foreground-color="#000000" fo:font-family="Nokia Pure Text" fo:background-color="#ffffff" fo:background-opacity="100%"/>
      <report:line-style report:line-style="nopen" report:line-weight="1" report:line-color="#000000"/>
     </report:field>
    </report:section>
   </report:detail>
  </report:body>
 </report:content>
 <connection type="internal" source="_160237"/>
</kexireport>

Moving to first record..
org.kde.kreport.core: Added "section_detail" to report "_160237"
org.kde.kreport.core: Report name is "_160237"
ID: 127
"executable"
"" "script1"
org.kde.kreport.core: ""
ASSERT failure in QVector<T>::at: "index out of range", file /usr/include/qt5/QtCore/qvector.h, line 393
Aborted

#4  0x00007ffff2fd3cf1 in qt_assert_x(char const*, char const*, char const*, int) (where=<optimized out>, what=<optimized out>, file=<optimized out>, line=<optimized out>) at global/qglobal.cpp:2974                                                                                
#5  0x00007fffd5af5f41 in QVector<KDbQueryColumnInfo*>::at(int) const (this=0x611b50, i=-1) at /usr/include/qt5/QtCore/qvector.h:393       
#6  0x00007fffd5af4f91 in SqliteCursor::value(int) (this=0x6a4090, i=-1)                                                                   
    at src/kdb/src/drivers/sqlite/SqliteCursor.cpp:336                                                                     
#7  0x00007fffcd56c7e2 in KexiDBReportData::value(QString const&) const (this=0x791bc0, fld=...)                                           
    at src/calligra-f/kexi/plugins/reports/kexidbreportdata.cpp:235                                                        
#8  0x00007fffcd4a5792 in KoReportPreRendererPrivate::renderSectionSize(KRSectionData const&) (this=0xc3afa0, sectionData=...)             
    at src/kreport/src/renderer/KoReportPreRenderer.cpp:300                                                                
#9  0x00007fffcd4a4d78 in KoReportPreRendererPrivate::renderDetailSection(KRDetailSectionData*) (this=0xc3afa0, detailData=0x785730)       
    at src/kreport/src/renderer/KoReportPreRenderer.cpp:190                                                                
#10 0x00007fffcd4a71b6 in KoReportPreRenderer::generate() (this=0x69d7c0)                                                                  
    at src/kreport/src/renderer/KoReportPreRenderer.cpp:581                                                                
#11 0x00007fffcd568758 in KexiReportView::afterSwitchFrom(Kexi::ViewMode) (this=0xc37400, mode=Kexi::AllViewModes)                         
    at src/calligra-f/kexi/plugins/reports/kexireportview.cpp:415                                                          
#12 0x00007ffff7d87dae in KexiWindow::switchToViewMode(Kexi::ViewMode, QMap<QString, QVariant>*, bool*) (this=0x75dac0, newViewMode=Kexi::DataViewMode, staticObjectArgs=0x0, proposeOpeningInTextViewModeBecauseOfProblems=0x7fffffffb42f)                                           
    at src/calligra-f/kexi/core/KexiWindow.cpp:541                                                                         
#13 0x00007ffff7d9876c in KexiPart::Part::openInstance(QWidget*, KexiPart::Item*, Kexi::ViewMode, QMap<QString, QVariant>*) (this=0x766760, parent=0x78dd70, item=0x5c5b60, viewMode=Kexi::DataViewMode, staticObjectArgs=0x0)                                                        
    at src/calligra-f/kexi/core/kexipart.cpp:281

@adam I'll push this code (with minimal proposed fixes). W need the kexi-frameworks9-staniek branch in a compleable state because merge with master is close.

staniek added a comment.EditedAug 30 2015, 11:33 PM

I fixed the above crash this way:

 QVariant KexiDBReportData::value ( const QString &fld ) const
 {
     int i = fieldNumber ( fld );
 
-    if ( d->cursor )
+    if (d->cursor && i >= 0)
         return d->cursor->value ( i );
 
     return QVariant();
 }

Moreover added a check for i < 0 in SqliteCursor::value() (Kdb).

staniek commandeered this revision.Aug 31 2015, 12:02 AM
staniek abandoned this revision.
staniek edited reviewers, added: piggz; removed: staniek.

Already Pushed to kexi-frameworks9-staniek calligra.git 3efb73483e54ce05f

This revision was automatically updated to reflect the committed changes.