Re: How to establish an activeConnetion on launching Openoffice.org BASE with embedded HSQLDB

Fernand Vanrie <[email protected]> Fri, 04 Mar 2011 09:41:49 +0100
Newsgroups gmane.comp.openoffice.dba.user
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------010303070703070001080608
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Rik,

Me again :-)

found a complete sub who works on HSQLDB but also not run from in the 
BaseDoc itself

Sub SaveToDB (path as string)
oSrcFilePath = ConvertToUrl(path)
oFileAccessService = createUnoService("com.sun.star.ucb.SimpleFileAccess")
oTextInputStream = createUnoService("com.sun.star.io.TextInputStream")
oTextInputStream.setInputStream(oFileAccessService.openFileRead(oSrcFilePath)) 

'xray oTextInputStream
ss =  oTextInputStream.readstring(array(),false)

    oDatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
    oDataSource = oDatabaseContext.getByName("ODF_test_PI")
    oConnection = oDataSource.GetConnection("","")

' prepare the Statement
  sSQL = "INSERT INTO TEST(HTML) VALUES(?)"
  Statement = Oconnection.PrepareStatement(sSQL)
' insert ss for ( ? ) placeholder 1

  Statement.setString(1,ss)

' write to Database ( Use iAccess to check Success if you want)
    iAccess = Statement.executeUpdate()
    print iAccess
     if iAccess = 1 then
   ' oSimpleFileAccess.kill( path )
    endif

sStatement = oconnection.createstatement
sSQL = "Select * from TEST where AUTO = 119"
   sStatement.execute(sSQL)
    resultset = sstatement.getresultset
    resultset.next
   ' xray resultset
    sHTML = resultset.getString(3)

    InsertHTMLContent(sHTML)

End Sub
> Rik,
>
> normaly for a OO-Dbase connectyed to MYSQL i use
>
>    oDB = CreateUnoService("com.sun.star.sdb.DatabaseContext")
>    if not oDB.hasbyname("OODbaseName")then
>    oDB.registerDatabaseLocation("mOODbaseName",converttoURL("Path to 
> OODbasename.odb")
>    endif
>    oConn = oDB.GetByName("OODbaseName").GetConnection("User","Password")
>
> Hope it helps
> Fernand
>> Hello together,
>> I'm new here, and i have a serious problem with my Base DB with 
>> embedded HSQLDB.
>> I'm not shure, if the problem exists 'cause of my Hard- and Software 
>> combination or if it's a serious bug in Base.
>> Using OOo 3.3-Base, Windows 7 and tryed out JRE 1.6.0_20/22/24 the 
>> problem exists with all of them:
>> When launching Openoffice.org BASE with embedded HSQLDB and directly 
>> *open a form* or dialog *via basic macro*,
>> *all inserted and changed datas are lost on closing the database 
>> document*.
>> That means, opening a Form in code does work, and I can see the datas 
>> of the HSQLDB in the form.
>> They also can be changed. Reopening the form via code shows the 
>> changed datas, i think they are written to cached tables, but not to 
>> the hard disk.
>> By closing the database-document, all added or changed datas are lost.
>>
>> With xray I found out, that there is no "activeConnection" into 
>> HSQLDB established by opening forms or dialogs on this way.
>> When i change once  into "Table view", then 
>> "thisComponent.currentcontroller.activeConnection" can be seen with 
>> Xray, otherwise it's a "Null Object".
>> In this case, all added and changed datas will be written to the 
>> embedded HSQLDB, nothing lost.
>> Does anybody know, how to establish the "activeConnection" via Basic?
>> Rik Hustede
>

--
-----------------------------------------------------------------
To unsubscribe send email to [email protected]
For additional commands send email to [email protected]
with Subject: help

--------------010303070703070001080608
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Rik,<br>
    <br>
    Me again :-)<br>
    <br>
    found a complete sub who works on <font size="2" color="#080000"
      face="Arial">HSQLDB but also not run from in the BaseDoc itself<br>
      <br>
    </font><font color="#080000"><font size="2"><font face="Arial">Sub
          SaveToDB (path as string) <br>
          oSrcFilePath = ConvertToUrl(path)<br>
          oFileAccessService =
          createUnoService("com.sun.star.ucb.SimpleFileAccess") <br>
          oTextInputStream =
          createUnoService("com.sun.star.io.TextInputStream")<br>
          oTextInputStream.setInputStream(oFileAccessService.openFileRead(oSrcFilePath))
          <br>
          'xray oTextInputStream<br>
          ss =&nbsp; oTextInputStream.readstring(array(),false)<br>
          <br>
          &nbsp;&nbsp; oDatabaseContext =
          createUnoService("com.sun.star.sdb.DatabaseContext") <br>
          &nbsp;&nbsp; oDataSource = oDatabaseContext.getByName("ODF_test_PI") <br>
          &nbsp;&nbsp; oConnection = oDataSource.GetConnection("","") <br>
          <br>
          ' prepare the Statement <br>
          &nbsp;sSQL = "INSERT INTO TEST(HTML) VALUES(?)"&nbsp; <br>
          &nbsp;Statement = Oconnection.PrepareStatement(sSQL)<br>
          ' insert ss for ( ? ) placeholder 1 <br>
          <br>
          &nbsp;Statement.setString(1,ss)<br>
          <br>
          ' write to Database ( Use iAccess to check Success if you
          want) <br>
          &nbsp;&nbsp; iAccess = Statement.executeUpdate()<br>
          &nbsp;&nbsp; print iAccess<br>
          &nbsp;&nbsp;&nbsp; if iAccess = 1 then<br>
          &nbsp; ' oSimpleFileAccess.kill( path )<br>
          &nbsp;&nbsp; endif<br>
          <br>
          sStatement = oconnection.createstatement&nbsp;&nbsp; <br>
          sSQL = "Select * from TEST where AUTO = 119"<br>
          &nbsp; sStatement.execute(sSQL) <br>
          &nbsp;&nbsp; resultset = sstatement.getresultset<br>
          &nbsp;&nbsp; resultset.next<br>
          &nbsp; ' xray resultset<br>
          &nbsp;&nbsp; sHTML = resultset.getString(3)<br>
          &nbsp;&nbsp;&nbsp;&nbsp; <br>
          &nbsp;&nbsp; InsertHTMLContent(sHTML)<br>
          <br>
          End Sub </font></font></font><br>
    <blockquote cite="mid:[email protected]" type="cite">
      <meta content="text/html; charset=ISO-8859-1"
        http-equiv="Content-Type">
      <title></title>
      Rik,<br>
      <br>
      normaly for a OO-Dbase connectyed to MYSQL i use<br>
      <br>
      &nbsp;&nbsp; oDB = CreateUnoService("com.sun.star.sdb.DatabaseContext")<br>
      &nbsp;&nbsp; if not oDB.hasbyname("OODbaseName")then<br>
      &nbsp;&nbsp; oDB.registerDatabaseLocation("mOODbaseName",converttoURL("Path
      to OODbasename.odb")<br>
      &nbsp;&nbsp; endif<br>
      &nbsp;&nbsp; oConn =
      oDB.GetByName("OODbaseName").GetConnection("User","Password")<br>
      <br>
      Hope it helps<br>
      Fernand<br>
      <blockquote cite="mid:5A2ABB1235B247419622F064D1640197@HustedePC"
        type="cite">
        <meta content="text/html; charset=ISO-8859-1"
          http-equiv="Content-Type">
        <meta name="GENERATOR" content="MSHTML 8.00.7600.16722">
        <div><font size="2" color="#080000" face="Arial">Hello together,</font></div>
        <div>&nbsp;</div>
        <div><font size="2" color="#080000" face="Arial">I'm new here,
            and i have a serious problem with my Base DB with embedded
            HSQLDB.</font></div>
        <div><font size="2" color="#080000" face="Arial">I'm not shure,
            if the problem exists 'cause of my Hard- and Software
            combination or if it's a serious bug&nbsp;in Base.</font></div>
        <div><font size="2" color="#080000" face="Arial">Using <font
              size="2" color="#080000" face="Arial">OOo 3.3-Base,
              Windows 7 and tryed out&nbsp;JRE 1.6.0_20/22/24 the
              problem&nbsp;exists with all of them:</font></font></div>
        <div><font size="2" color="#080000" face="Arial">&nbsp;</font></div>
        <div>
          <div><font size="2" color="#080000" face="Arial"><font
                size="2" color="#080000" face="Arial">When launching
                Openoffice.org BASE with embedded HSQLDB and directly <strong>open
                  a form</strong> or dialog <strong>via basic macro</strong>,
              </font></font></div>
          <div><font size="2" color="#080000" face="Arial"><font
                size="2" color="#080000" face="Arial"><strong>all
                  inserted and changed datas are lost on closing the
                  database document</strong>.</font></font></div>
        </div>
        <div><font size="2" color="#080000" face="Arial">&nbsp;</font></div>
        <div><font size="2" color="#080000" face="Arial"><font size="2"
              color="#080000" face="Arial">That means, opening&nbsp;a Form in
              code does work, and I can see the datas of the HSQLDB in
              the form. </font></font>
          <div><font size="2" color="#080000" face="Arial"><font
                size="2" color="#080000" face="Arial"><font size="2"
                  color="#080000" face="Arial">They also can be changed.
                  Reopening the form via code shows the changed datas, i
                  think they are written to cached tables, but not to
                  the hard disk.</font></font></font></div>
          <div><font size="2" color="#080000" face="Arial"><font
                size="2" color="#080000" face="Arial"><font size="2"
                  color="#080000" face="Arial">By closing the
                  database-document, all added or changed datas are
                  lost.</font></font></font></div>
        </div>
        <div><font size="2" color="#080000" face="Arial"><font size="2"
              color="#080000" face="Arial"><br>
              With xray I found out, that there is no "activeConnection"
              into HSQLDB established by opening forms or dialogs&nbsp;on
              this way.</font></font></div>
        <div><font size="2" color="#080000" face="Arial"><font size="2"
              color="#080000" face="Arial">&nbsp;</font></font></div>
        <div>
          <div><font size="2" color="#080000" face="Arial"><font
                size="2" color="#080000" face="Arial"><font size="2"
                  color="#080000" face="Arial">When i change once &nbsp;into
                  "Table view", t</font><font size="2" color="#080000"
                  face="Arial">hen
                  "thisComponent.currentcontroller.activeConnection" can
                  be seen&nbsp;with Xray, otherwise it's a "Null Object".</font></font></font></div>
          <div><font size="2" color="#080000" face="Arial"><font
                size="2" color="#080000" face="Arial"><font size="2"
                  color="#080000" face="Arial">In this case, all added
                  and changed datas will be written to the embedded
                  HSQLDB, nothing lost.</font></font></font></div>
          <div><font size="2" color="#080000" face="Arial"><font
                size="2" color="#080000" face="Arial">&nbsp;</font></font></div>
        </div>
        <font size="2" color="#080000" face="Arial"> </font>
        <div>
          <div><font size="2" color="#080000" face="Arial">&nbsp;</font></div>
        </div>
        <div><font size="2" color="#080000" face="Arial"><font size="2"
              color="#080000" face="Arial">Does anybody know, how to
              establish the "activeConnection" via Basic?</font></font></div>
        <div><font size="2" color="#080000" face="Arial">&nbsp;</font></div>
        <div><font size="2" color="#080000" face="Arial">&nbsp;</font></div>
        <div><font size="2" color="#080000" face="Arial">Rik Hustede</font></div>
        <div><font size="2" color="#080000" face="Arial">&nbsp;</font></div>
        <div><font size="2" color="#080000" face="Arial">&nbsp;</font></div>
      </blockquote>
      <br>
    </blockquote>
    <br>
  </body>
</html>

--------------010303070703070001080608--