# Database and Paintable Canvas Refresh

**URL:** <https://forum.inductiveautomation.com/t/database-and-paintable-canvas-refresh/21865>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [January 14, 2019, 4:14pm UTC](https://forum.inductiveautomation.com/t/database-and-paintable-canvas-refresh/21865 "2019-01-14T16:14:51Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 14, 2019, 4:34pm UTC](https://forum.inductiveautomation.com/t/database-and-paintable-canvas-refresh/21865/2 "2019-01-14T16:34:59Z")

</div>

Where is this code? In the paint method? If so, break it up so your db query runs separately (on some propertyChange) to obtain and set the client property. Say, on your Documents table, have a propertyChange that does most of the work, but only on image change, like so:

```auto
if event.propertyName == 'id':
	from javax.imageio import ImageIO
	from java.io import ByteArrayInputStream

	blob = system.db.runPrepQuery(“SELECT file FROM magna_silao.documents where id= ?”, [event.newValue])
	bytes = blob[0][0]
	image = ImageIO.read(ByteArrayInputStream(bytes))
	canvas = event.source.parent.getComponent("Paintable canvas")
	canvas.putClientProperty("cached-image", image)
	canvas.repaint()

```

Then your paint event only has to paint, and only if the cached image has been processed:

```auto
image = self.getClientProperty(“cached-image”)
if image:
	event.graphics.drawImage(image, 0, 0, event.source)

```

Note that painting can be called really often – any time the anything obscures the canvas or updated. Or various window/container events.

{ Also, when pasting code or other plain text in the forum, use a line with just three backquotes above the code, and again below the code, so it formats nicely. }

---

_[View the full topic](https://forum.inductiveautomation.com/t/database-and-paintable-canvas-refresh/21865)._
