Display images stored in Relational DB

classic Classic list List threaded Threaded
2 messages Options
Thomas G. Apostolou Thomas G. Apostolou
Reply | Threaded
Open this post in threaded view
|

Display images stored in Relational DB

Hello all,

I try to display some images stored in SQL Server 2K.
What i do is:

I have an External Method "GetPrList" witch is connected to a python
module that reads like this
def GetPrListData(self, sysDSN="Test_A_Voisys", usr="sa",
mypass="voisys"):
        id = self.id
        import dbi
        import odbc
        connection=odbc.odbc(sysDSN+'/'+usr+'/'+mypass)
        cur=connection.cursor()
        sSQL='SELECT M.CODE,M.NAME,X.SODATA FROM dbo.MTRL M JOIN
dbo.XTRDOCDATA
X ON M.MTRL=X.REFOBJID WHERE X.SOSOURCE=51 AND M.MTRGROUP=3'
        cur.execute(sSQL)
        data=cur.fetchall()
        cur.close()
        connection.close()
        return data

X.SODATA is jpg stored in SQL 2K in a field degined as [SODATA] [image]
NULL

The above select returns -executed from within PythonWin- the folowing:
[('ACC.ART.0001', '\xd3\xc5\xd4 \xc2\xc9\xc4\xc5\xd3 &
\xd0\xc1\xce\xc9\xcc\xc1\xc4\xc9\xc1 \xcc\xc5 \xc5\xcb\xc1\xd4 andy',
<DbiRaw object at 0x0099D2A0>), ('ACC.CO3.0001', 'BATTERY
\xcc\xcf\xcb\xd5\xc2\xc4\xcf\xd5 12V', <DbiRaw object at 0x0099D2D0>),
('ACC.CO3.0002', 'ME\xcb\xc1\xcd\xc9 \xcf\xca\xc9 10i/12i/14e', <DbiRaw
object at 0x0099D2C0>)]

Then from a DTML Method "ShowResults" i call the above External Method
"GetPrList" and show its results in a table.
ShowResults reads like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      lang="en">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<script type="text/javascript"
src="/plone_javascript_variables.js"></script>
<script type="text/javascript" src="/plone_javascripts.js"></script>
    <!-- Column style sheet. -->
    <style type="text/css" media="screen"><!-- @import
url(/ploneColumns.css); --></style>
    <!-- Main style sheets for CSS2 capable browsers -->
    <style type="text/css" media="screen"><!-- @import url(/plone.css);
--></style>
    <!-- Custom style sheet if available -->
    <style type="text/css" media="all"><!-- @import
url(/ploneCustom.css); --></style>
    <!-- Disable IE6 image toolbar -->
    <meta http-equiv="imagetoolbar" content="no" />
</head>
<dtml-var standard_html_header>
<table id="sortable" class="listing" summary="Content listing"
cellpadding="0" cellspacing="0">
  <thead>
    <tr>
      <th class="">
        Κωδικός
      </th>
      <th class="">
        Ονομασία
      </th>
      <th class="">
        Εικόνα
      </th>
    </tr>
  </thead>
  <tbody>
    <dtml-in expr="GetPrList(sysDSN=dsnName, usr=usrID,
mypass=passWD)">
      <dtml-if sequence-even>
        <tr class="even">
      <dtml-else>
        <tr class="odd">
      </dtml-if>
      <dtml-in sequence-item>
        <td><dtml-var sequence-item> </td>
      </dtml-in>
      </tr>
    </dtml-in>
  </tbody>
</table>
<dtml-var standard_html_footer>

dsnName, usrID, passWD are properties with values of a folder i use
with
aquisition when i call DTML Method "ShowResults"

The problem is that i get a "pythonw.exe" Debug-Send Error Report-Don't
Send window and zope server breaks down. ( yes i use windows Xp Pro,
Zope 2.7.0, Plone 2.0.5, Python 2.3.3)

Thanks in advance


Thomas G. Apostolou
Software Engineer
Θωμάς Γ. Αποστόλου
Μηχανικός Λογισμικού



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Nikos Papagrigoriou Nikos Papagrigoriou
Reply | Threaded
Open this post in threaded view
|

Re: Display images stored in Relational DB

First of all, I have to mention that the best solution for your problem is to combine a Page Template and a python script. To connect to the database through zope look here: http://www.egenix.com/files/python/mxODBC-Zope-DA.html. In my opinion you shouldn't use an external method to access your database.

In your DTML Method I noticed that you define the headers that plone needs and then you call <dtml-var standard_html_header> and at the end you call <dtml-var standard_html_footer>. This is wrong because <dtml-var standard_html_header> defines again the header in the body of the report. Nevertheless, this may cause troubles in rendering the DTML Method to a html page.

You have to test your external method before you call it through a DTML Method. Look here:
http://www.plope.com/Books/2_7Edition/BasicObject.stx#2-27

An abstract from the above link:

Testing An External Method Object

You can test an External Method in the Workspace frame by clicking the Test tab from the External Method's management screen. When you test an external method, the output of the external method will be displayed in your browser. Unlike Script (Python) objects, External Methods provide no mechanism for specifying parameter values during testing. However, like Script (Python) objects, their output is influenced by values in a query string when you visit them directly.


On 10/18/05, Thomas G. Apostolou <[hidden email]> wrote:
Hello all,

I try to display some images stored in SQL Server 2K.
What i do is:

I have an External Method "GetPrList" witch is connected to a python
module that reads like this
def GetPrListData(self, sysDSN="Test_A_Voisys", usr="sa",
mypass="voisys"):
        id = self.id
        import dbi
        import odbc
        connection=odbc.odbc(sysDSN+'/'+usr+'/'+mypass)
        cur=connection.cursor ()
        sSQL='SELECT M.CODE,M.NAME,X.SODATA FROM dbo.MTRL M JOIN
dbo.XTRDOCDATA
X ON M.MTRL=X.REFOBJID WHERE X.SOSOURCE=51 AND M.MTRGROUP=3'
        cur.execute(sSQL)
        data= cur.fetchall()
        cur.close()
        connection.close()
        return data

X.SODATA is jpg stored in SQL 2K in a field degined as  [SODATA] [image]
NULL

The above select returns -executed from within PythonWin- the folowing:
[('ACC.ART.0001', '\xd3\xc5\xd4 \xc2\xc9\xc4\xc5\xd3 &
\xd0\xc1\xce\xc9\xcc\xc1\xc4\xc9\xc1 \xcc\xc5 \xc5\xcb\xc1\xd4 andy',
<DbiRaw object at 0x0099D2A0>), ('ACC.CO3.0001', 'BATTERY
\xcc\xcf\xcb\xd5\xc2\xc4\xcf\xd5 12V', <DbiRaw object at 0x0099D2D0>),
('ACC.CO3.0002', 'ME\xcb\xc1\xcd\xc9 \xcf\xca\xc9 10i/12i/14e', <DbiRaw
object at 0x0099D2C0>)]

Then from a DTML Method "ShowResults" i call the above External Method
"GetPrList" and show its results in a table.
ShowResults reads like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      lang="en">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<script type="text/javascript"
src="/plone_javascript_variables.js"></script>
<script type="text/javascript" src="/plone_javascripts.js"></script>
    <!-- Column style sheet. -->
    <style type="text/css" media="screen"><!-- @import
url(/ploneColumns.css); --></style>
    <!-- Main style sheets for CSS2 capable browsers -->
    <style type="text/css" media="screen"><!-- @import url(/plone.css);
--></style>
    <!-- Custom style sheet if available -->
    <style type="text/css" media="all"><!-- @import
url(/ploneCustom.css); --></style>
    <!-- Disable IE6 image toolbar -->
    <meta http-equiv="imagetoolbar" content="no" />
</head>
<dtml-var standard_html_header>
<table id="sortable" class="listing" summary="Content listing"
cellpadding="0" cellspacing="0">
  <thead>
    <tr>
      <th class="">
        Κωδικός
      </th>
      <th class="">
        Ονομασία
      </th>
      <th class="">
        Εικόνα
      </th>
    </tr>
  </thead>
  <tbody>
    <dtml-in expr="GetPrList(sysDSN=dsnName, usr=usrID,
mypass=passWD)">
      <dtml-if sequence-even>
        <tr class="even">
      <dtml-else>
        <tr class="odd">
      </dtml-if>
      <dtml-in sequence-item>
        <td><dtml-var sequence-item> </td>
      </dtml-in>
      </tr>
    </dtml-in>
  </tbody>
</table>
<dtml-var standard_html_footer>

dsnName, usrID, passWD are properties with values of a folder i use
with
aquisition when i call DTML Method "ShowResults"

The problem is that i get a "pythonw.exe" Debug-Send Error Report-Don't
Send window and zope server breaks down. ( yes i use windows Xp Pro,
Zope 2.7.0, Plone 2.0.5, Python 2.3.3)

Thanks in advance


Thomas G. Apostolou
Software Engineer
Θωμάς Γ. Αποστόλου
Μηχανικός Λογισμικού



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users



--
Nikos Papagrigoriou <[hidden email]>
http://www.papagrigoriou.gr