Пример #1
0
    def test_pnunpacker(self) -> None:
        """Test eneboopkgs load."""
        from pineboolib.qsa import qsa
        from pineboolib.fllegacy import systype
        import os

        qsa_sys = systype.SysType()
        path = fixture_path("principal.eneboopkg")
        self.assertTrue(os.path.exists(path))
        qsa_sys.loadModules(path, False)
        qsa_sys.registerUpdate(path)

        qry = qsa.FLSqlQuery()
        qry.setTablesList("flfiles")
        qry.setSelect("count(nombre)")
        qry.setFrom("flfiles")
        qry.setWhere("1=1")
        self.assertTrue(qry.exec_())
        self.assertTrue(qry.first())
        self.assertEqual(qry.value(0), 148)

        qry_2 = qsa.FLSqlQuery()
        qry_2.setTablesList("flfiles")
        qry_2.setSelect("nombre")
        qry_2.setFrom("flfiles")
        qry_2.setWhere("nombre='impuestos.py'")
        self.assertTrue(qry_2.exec_())
        self.assertTrue(qry_2.first())
        self.assertEqual(qry_2.value(0), "impuestos.py")
Пример #2
0
    def afterCommit_flfiles(self, cur_files_: "isqlcursor.ISqlCursor") -> bool:
        """After commit flfiles."""

        if cur_files_.modeAccess() != cur_files_.Browse:
            _qry = qsa.FLSqlQuery()
            _qry.setTablesList(u"flserial")
            _qry.setSelect(u"sha")
            _qry.setFrom(u"flfiles")
            _qry.setForwardOnly(True)
            _serial_value = cur_files_.valueBuffer(u"sha")
            if _qry.exec_():
                if _qry.first():
                    util = qsa.FLUtil()
                    _v = util.sha1(_qry.value(0))
                    while _qry.next():
                        if _qry.value(0) is not None:
                            _v = util.sha1(_v + _qry.value(0))

                    _serial_value = _v

            _cur_serial = qsa.FLSqlCursor(u"flserial")
            _cur_serial.select()
            if _cur_serial.first():
                _cur_serial.setModeAccess(_cur_serial.Edit)
            else:
                _cur_serial.setModeAccess(_cur_serial.Insert)
            _cur_serial.refreshBuffer()
            _cur_serial.setValueBuffer(u"sha", _serial_value)
            _cur_serial.commitBuffer()

        return True
Пример #3
0
    def test_kugar_parser_1(self) -> None:
        """Test parser."""

        from pineboolib.qsa import qsa

        from pineboolib.plugins.mainform.eneboo import eneboo
        import os

        application.PROJECT.main_form = eneboo
        # application.project.main_form.mainWindow = application.project.main_form.MainForm()
        # application.project.main_form.mainWindow.initScript()
        # application.project.main_window = application.project.main_form.mainWindow

        application.PROJECT.main_window = application.PROJECT.main_form.MainForm(
        )  # type: ignore
        application.PROJECT.main_window.initScript()

        qsa_sys = qsa.sys
        path = fixture_path("principal.eneboopkg")
        self.assertTrue(os.path.exists(path))
        qsa_sys.loadModules(path, False)
        qsa.from_project("flfactppal").iface.valoresIniciales()

        cur_paises = qsa.FLSqlCursor("paises")
        """
        cur_paises.setModeAccess(cur_paises.Insert)
        cur_paises.refreshBuffer()
        cur_paises.setValueBuffer("codpais", "ES")
        cur_paises.setValueBuffer("nombre", "ESPAÑA")
        self.assertTrue(cur_paises.commitBuffer())
        cur_paises.setModeAccess(cur_paises.Insert)
        cur_paises.refreshBuffer()
        cur_paises.setValueBuffer("codpais", "PT")
        cur_paises.setValueBuffer("nombre", "PORTUGAL")
        self.assertTrue(cur_paises.commitBuffer())
        """
        cur_paises.select("1=1")
        cur_paises.first()
        init_ = cur_paises.valueBuffer("codpais")
        cur_paises.last()
        last_ = cur_paises.valueBuffer("codpais")
        qry_paises = qsa.FLSqlQuery("paises")
        qry_paises.setValueParam("from", init_)
        qry_paises.setValueParam("to", last_)

        rpt_viewer_ = qsa.FLReportViewer()
        rpt_viewer_.setReportTemplate("paises")
        rpt_viewer_.setReportData(qry_paises)

        rpt_viewer_.renderReport()
        if rpt_viewer_.rptEngine_ and hasattr(rpt_viewer_.rptEngine_,
                                              "parser_"):
            pdf_file = rpt_viewer_.rptEngine_.parser_.get_file_name()

        self.assertTrue(pdf_file)
Пример #4
0
def valorPorClave(tabla: str, campo: str, where: str) -> Any:
    """Return a value from database."""
    valor = None
    query = qsa.FLSqlQuery()
    query.setTablesList(tabla)
    query.setSelect(campo)
    query.setFrom(tabla)
    query.setWhere(qsa.ustr(where, u";"))
    query.exec_()
    if query.next():
        valor = query.value(0)
    return valor
Пример #5
0
    def test_report_data(self) -> None:
        """Test eneboopkgs load."""
        from pineboolib.qsa import qsa
        import os

        path = fixture_path("principal.eneboopkg")
        self.assertTrue(os.path.exists(path))
        qsa.sys.loadModules(path, False)

        qry = qsa.FLSqlQuery()
        qry.setTablesList("flfiles")
        qry.setSelect("count(nombre)")
        qry.setFrom("flfiles")
        qry.setWhere("1=1")
        self.assertTrue(qry.exec_())
        self.assertTrue(qry.first())
        res = qsa.sys.toXmlReportData(qry)
        self.assertTrue(res.toString(2).find("</KugarData>") > -1)
Пример #6
0
    def test_flsqlquery_date_null(self) -> None:
        """Test FLSqlQuery date null."""

        from pineboolib.qsa import qsa

        cursor = qsa.FLSqlCursor("fltest")
        cursor.setModeAccess(cursor.Insert)
        cursor.refreshBuffer()
        self.assertTrue(cursor.commitBuffer())

        qry = qsa.FLSqlQuery()
        qry.setTablesList("fltest")
        qry.setSelect("date_field")
        qry.setFrom("fltest")
        qry.setWhere("1=1 LIMIT 1")
        self.assertTrue(qry.exec_())
        self.assertTrue(qry.first())
        self.assertEqual(str(qry.value(0)), "")
Пример #7
0
    def test_basic_4(self) -> None:
        """Test basic test 4."""
        from pineboolib.qsa import qsa
        from pineboolib import application
        from pineboolib.application.metadata import pntablemetadata, pnfieldmetadata
        import os

        qsa_sys = qsa.sys
        path = fixture_path("principal.eneboopkg")
        self.assertTrue(os.path.exists(path))
        qsa_sys.loadModules(path, False)
        widget = qsa.from_project("flfactppal")
        widget.iface.valoresIniciales()
        cur_clientes = qsa.FLSqlCursor("clientes")
        cur_clientes.setModeAccess(cur_clientes.Insert)
        cur_clientes.refreshBuffer()
        # cur_clientes.setValueBuffer("codigo", "000001")
        cur_clientes.setValueBuffer("nombre", "cliente de prueba")
        cur_clientes.setValueBuffer("cifnif", "01234567H")
        cur_clientes.setValueBuffer("codserie", "A")
        self.assertTrue(cur_clientes.commitBuffer())
        cur_clientes.commit()
        cur_clientes.conn().doTransaction(cur_clientes)

        mtd_tareas = pntablemetadata.PNTableMetaData("tareas")
        field_01 = pnfieldmetadata.PNFieldMetaData(
            "idtarea",
            "Id",
            False,
            True,
            "serial",
            0,
            True,
            True,
            True,
            0,
            0,
            True,
            True,
            False,
            None,
            False,
            False,
            False,
            True,
            False,
        )
        field_02 = pnfieldmetadata.PNFieldMetaData(
            "nombre",
            "Nombre",
            False,
            False,
            "string",
            10,
            False,
            True,
            True,
            0,
            0,
            False,
            False,
            False,
            None,
            False,
            False,
            True,
            False,
            False,
        )
        field_03 = pnfieldmetadata.PNFieldMetaData(
            "fechaini",
            "Fecha Inicial",
            True,
            False,
            "date",
            0,
            False,
            True,
            True,
            0,
            0,
            False,
            False,
            False,
            None,
            False,
            False,
            True,
            False,
            False,
        )
        field_04 = pnfieldmetadata.PNFieldMetaData(
            "fechafinal",
            "Fecha Final",
            True,
            False,
            "date",
            0,
            False,
            True,
            True,
            0,
            0,
            False,
            False,
            False,
            None,
            False,
            False,
            True,
            False,
            False,
        )
        mtd_tareas.addFieldMD(field_01)
        mtd_tareas.addFieldMD(field_02)
        mtd_tareas.addFieldMD(field_03)
        mtd_tareas.addFieldMD(field_04)
        self.assertEqual(mtd_tareas.fieldListArray(False),
                         ["idtarea", "nombre", "fechaini", "fechafinal"])
        application.PROJECT.conn_manager.manager(
        ).cache_metadata_["tareas"] = mtd_tareas
        application.PROJECT.conn_manager.manager().createTable("tareas")
        self.assertTrue(
            application.PROJECT.conn_manager.manager().existsTable("tareas"))

        cur_tareas = qsa.FLSqlCursor("tareas")
        self.assertEqual(
            cur_tareas.metadata().fieldListArray(False),
            ["idtarea", "nombre", "fechaini", "fechafinal"],
        )

        cur_tareas.setModeAccess(cur_tareas.Insert)
        cur_tareas.refreshBuffer()
        # cur_tareas.setValueBuffer("idtarea", 1)
        cur_tareas.setValueBuffer("nombre", "prueba1")
        self.assertTrue(cur_tareas.commitBuffer())
        cur_tareas.setModeAccess(cur_tareas.Insert)
        cur_tareas.refreshBuffer()
        # cur_tareas.setValueBuffer("idtarea", 2)
        cur_tareas.setValueBuffer("nombre", "prueba2")
        cur_tareas.setValueBuffer("fechaini", str(qsa.Date()))
        cur_tareas.setValueBuffer("fechafinal", str(qsa.Date()))
        self.assertTrue(cur_tareas.commitBuffer())
        cur_tareas.setModeAccess(cur_tareas.Insert)
        cur_tareas.refreshBuffer()
        # cur_tareas.setValueBuffer("idtarea", 3)
        cur_tareas.setValueBuffer("nombre", "prueba3")
        cur_tareas.setValueBuffer("fechaini", str(qsa.Date()))
        cur_tareas.setValueBuffer("fechafinal", str(qsa.Date()))
        self.assertTrue(cur_tareas.commitBuffer())
        cur_tareas.setModeAccess(cur_tareas.Insert)
        cur_tareas.refreshBuffer()
        cur_tareas.setValueBuffer("nombre", "prueba4")
        cur_tareas.setValueBuffer("fechaini", str(qsa.Date()))
        self.assertTrue(cur_tareas.commitBuffer())
        cur_tareas.setModeAccess(cur_tareas.Insert)
        cur_tareas.refreshBuffer()
        # cur_tareas.setValueBuffer("idtarea", 3)
        cur_tareas.setValueBuffer("nombre", "prueba5")
        cur_tareas.setValueBuffer("fechafinal", str(qsa.Date()))
        self.assertTrue(cur_tareas.commitBuffer())
        cur_tareas.commit()

        qry = qsa.FLSqlQuery()
        qry.setSelect("idtarea,nombre,fechaini,fechafinal")
        qry.setFrom("tareas")
        qry.setWhere("1=1")
        qry.setOrderBy("idtarea")
        self.assertTrue(qry.exec_())
        self.assertTrue(qry.first())
        self.assertEqual(qry.value("fechaini"), "")
        self.assertEqual(qry.value("fechafinal"), "")
        self.assertTrue(qry.next())
        self.assertNotEqual(qry.value("fechaini"), "")
        self.assertNotEqual(qry.value("fechafinal"), "")
        self.assertTrue(qry.next())
        self.assertNotEqual(qry.value("fechaini"), "")
        self.assertNotEqual(qry.value("fechafinal"), "")
        self.assertTrue(qry.next())
        self.assertNotEqual(qry.value("fechaini"), "")
        self.assertEqual(qry.value("fechafinal"), "")
        self.assertTrue(qry.next())
        self.assertEqual(qry.value("fechaini"), "")
        self.assertNotEqual(qry.value("fechafinal"), "")