Entries tagged sql

Show Pictures in a Form on a Table with Report in APEX

Posted on 10. Dezember 2013 Comments

The table is called WPDBD_TEIL. The primary key is TID. In WPDBD_TEIL there is a column called BILD(german: picture/image) from type BLOB.

First click on your form and keep the name of the picture in mind. In this case, it’s P9_BILD.
report_bild

Then go to your report, click on edit for the whole report and use the following code

apex_editreport

select "TID", 
"TNAME",
"PREIS",
decode(nvl(dbms_lob.getlength("BILD"),0),0,null, '<img height="100px" width="100px" src="'||apex_util.get_blob_file_src('P9_BILD',TID)||'" />') "BILD"
from "#OWNER#"."WPDBD_TEIL"

If you’d open the report now, you only get the HTML Code. So you have to change the way APEX displays the entry. So go to the report, click on BILD and change Display as Text to Report Standard Column

 

edit_bildstandardreportcolumn

 

The form I used was the following.

formreport

Also, in the last page of creating the form, you have to chose your own primary key, not the ROWID.

 

primarykeyapexform

 

Owncloud News Reader Error after update to 5.0.11

Posted on 21. Oktober 2013 Comments

After updating to owncloud 5.0.11 I got the following error in my Owncloud News Reader:

Screenshot_2013-10-21-10-20-56

(For Google: A Toast saying „End of input at line 1 column 1“)

In my owncloud instance, I got an error in the administrator menu saying:

SQLSTATE[HY000]: General error: 1 no such column: feeds.articles_per_update at db.php#391

I updated the owncloud instance and app framework/news app but it still showed me that everything was uptodate, even when 5.0.12 was released. Via phpMyAdmin I could see that the feeds were still in the database but I couldn’t see them in the web app or Android app. So I just deleted the owncloud folder, downloaded the new .tar.bz2 from owncloud.org, removed the oc_news tables(do not delete e.g. the contacts or bookmarks!). Then I changed my username in oc_users, used my old username as my new username and reinstalled owncloud, this time version 5.0.12.  I could then delete the old (changed) username via the admin panel.

This is the third time I had to reinstall owncloud, because the update mechanism didn’t work properly… And yes, as advised, I did deactivate the news app and app framework for the update process 😉

I just had a look at the SQL-statements from my last backup and saw that articles_per_update is supposed to be a column in oc_news_feeds in the new version of the news app. Somehow, the owncloud update process didn’t update the news app or didn’t trigger a 3rd-party update process. Anyways, I guess this could also be solved by just adding this column manually:
`articles_per_update` bigint(20) NOT NULL DEFAULT '0'

SQLDeveloper with Ubuntu 12.04, alien and the .rpm-file

Posted on 30. September 2013 Comments

There are a couple of tutorials[1] of how to install Oracles SQLDeveloper and they all say to install the sqldeveloper-XXX-no-jre.zip, in this case sqldeveloper-3.2.20.09.87-no-jre.zip. I didn’t read it because my first idea was the following and it also worked: It’s possible to download the .rpm-file and convert it with alien. You might have to install it with

sudo apt-get install alien

then

alien sqldeveloper-3.2.20.09.87-1.noarch.rpm
dpkg -i sqldeveloper_3.2.20.09.87-2_all.deb

You can then start the sqldeveloper. It will ask you for the Java Path which is usually /usr/lib/jvm/java-6-openjdk and give you some kind of error, which didn’t seem to have any impact.

repat@laptop:~$ sqldeveloper
Oracle SQL Developer
Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
Type the full pathname of a J2SE installation (or Ctrl-C to quit), the path will be stored in ~/.sqldeveloper/jdk
/usr/lib/jvm/java-6-openjdk
/opt/sqldeveloper/sqldeveloper/bin/../../ide/bin/launcher.sh: Zeile 455: /home/repat/.sqldeveloper/jdk: Datei oder Verzeichnis nicht gefunden

[1] e.g. Oracle Forum, Linux Sagas, Software in a bottle

MySQL Server absichern

Posted on 7. März 2012 Comments

Was bei einem Webhoster der Admin automatisch übernimmt, muss man bei einer Installation z.B. auf dem eigenen Homeserver selbst machen. Ich gehe hier von einem über Paketquellen installierten MySQL Server der Version 5.0.57 auf einem Apache der Version 2.2.10 unter SuSE Linux Enterprise Server(SLES) aus. Wer einigermaßen englisch spricht dem ist auch Kapitel 2.18.2. Securing the Initial MySQL Accounts der offiziellen MySQL Dokumentation empfohlen. Bevor man startet natürlich den MySQL Server starten.

Als allererstes sollte man Passwörter setzen, dazu loggt man sich ein:

mysql -u root

Dann bekommt man so eine shell:

 mysql>

Der Befehl um sich die Benutzer anzugucken ist:

SELECT User,Host,Password FROM mysql.user

Der beliebte SELECT * Befehl ist hier nicht zu empfehlen, da mysql.user wie man schön an

describe mysql.user;

merkt, 37 Spalten hat und somit auf den meisten Bildschirm die Konsole sprengt;-)
Hier sollte jetzt eigentlich nur der root-Benutzer(der alles kann) auftauchen und evtl. einige anonyme Accounts. Die bekommt man mit folgendem Befehl gelöscht:

DELETE FROM mysql.user WHERE User='' AND Password=''

Sollte man einen User hinzugefügt haben kann(Empfohlen! Nie den root User für Anwendungen nehmen), man mit folgendem Befehl die Rechte feststellen.

SHOW GRANTS FOR 'user'@'localhost'

Alternativ gehen die folgenden Befehle:

SELECT User,Select_priv,Insert_priv,Update_priv,Delete_priv FROM mysql.user;

Die entsprechenden Rechte aus DDL, DCL und DML kann man dem oben genannten describe Befehl entnehmen. Der User hatte bei mir standardmässig Rechte um von jedem Host aus zu verbinden. Dies wird durch den Wildcard % vermerkt, der sich bei in der Host Spalte vom User befindet. Möchte man die üblichen Web-Applikationen auf dem Server laufen lassen, z.B. CMS wie WordPress für Blogs oder Drupal für Websites, braucht man keine Verbindung von außerhalb sondern nur von localhost(dort liegen die PHP-Dateien von denen die Abfragen kommen, der User kann auf dem ganzen Internet zugreifen, bzw. das ist Sache des Apaches)

DELETE FROM mysql.user WHERE Host='%';

Jetzt kann es sein, dass der User oder auch root nur für einige Hosts ein Passwort hat. Deswegen sollte man für alle Hosts den folgenden Befehl ausführen:

 SET PASSWORD FOR 'root'@'HOST' = PASSWORD('newpwd');

Wenn man Initialisierungsanleitungen gefolgt ist hat man eventuell eine Datebank namens test. Dies lässt sich ganz einfach feststellen:

SHOW DATABASES;

Mit diesem drop-Befehl löscht man diese unnötige Datenbank:

DROP DATABASE test;

Daneben gibts es noch die eben benutze mysql und die information_schema Datenbank, die man nicht löschen sollte.

Ein weiterer Tweak ist, den Benutzernamen von root zu ändern, um automatisierten brute-force Attacken auf das root Passwort aus dem Weg zu gehen:

UPDATE mysql.user SET User='myNameForRoot' WHERE User='root';

Zum Reload der ganzen Berechtigungen, z.B. nach Anlegen eines neuen Users muss man mit folgendem Befehl die Rechte neu einlesen

FLUSH PRIVILEGES;

Ausserdem gibt es noch die Möglichkeit mysqld in einer chroot Umgebung laufen zu lassen, dazu vielleicht später mehr.
Quellen

  • www.pantz.org/software/mysql/mysqlcommands.html
  • http://dev.mysql.com/doc/refman/5.1/de/delete.html
  • http://dev.mysql.com/doc/refman/4.1/en/adding-users.html
  • http://dev.mysql.com/doc/refman/5.0/en/default-privileges.html