Have you tried updating something simple as following?
update category_tmp set last_update=NOW()
where category_id in (
select category_id from category_tmp where name like 'A%'
);
In MySQL you will get an error like this:
Error Code: 1093. You can't specify target table 'category_tmp' for update in FROM clause.
So it says that you can't use the same update TABLE name within the sub query in where condition. The trick to get around this is to use another sub query in the where clause so it won't see the TABLE name being used! Here is a workaround:
update category_tmp set last_update=NOW()
where category_id in (
select category_id from (
select category_id from category_tmp where name like 'A%'
) ID_LIST
);
Noticed that in MySQL, you must name your sub query result such as ID_LIST, in order for it to be re-select it again on the outer query! Otherwise it will error out with this:
Error Code: 1248. Every derived table must have its own alias
My personal journal on software development and practical programming.
Monday, October 12, 2015
Sunday, October 11, 2015
mac: MacBook Air is not displaying scroll bar on Finder
For odd reason that I don't see scrollbar shows up on Finder in MacBook Air when I have a long list of files. Can't scroll down with my trackpad, but I can do it with "Fn" + Down Arrow key though. To fix this, I have to go into System Preference, General and set "Show scroll bar" to "Always".
python: Setup Python on Mac
Setup Python 2
The default MacOS should already come with latest Python 2.7. It will be pre-installed along with some pyobjc packages as well.
If you like to play around with python and external packages, it's best not to touch the original Python install from the System. Unfortunately, this Python 2.7 does not come with pip nor virtualenv packages to help setup separate environment! So it's okay to install these two into the system first. The easiest to setup is simply download get-pip.py from https://bootstrap.pypa.io/get-pip.py, then run
bash> sudo python get-pip.py
With this, you may now able install virtualenv
bash> sudo /usr/local/bin/pip install virtualenv
Now you can setup Python2 virtual env on a separate directory.
bash> python -m virtualenv mypy
bash> source mypy/bin/activate
(mypy) bash> python -c 'import sys; print sys.path'
You should able to verify the output above that you are indeed using your own setup of an isolated Python2 env, and it even has your own pip installed list, so you won't mess up the built-in System version of python!
Setup Python 3
The MacOS comes with latest Python 2.7, but no Python3. You can download the latest Python3 from python.org site and install it. It will give you a new 'python3' command so not to conflict with your existing Python. (NOTE: It's best not to remove or override the default Python2.7 that comes with the system!) But if you want to use 'python' command for Python3 for dev, then I suggest you create a new virtual environment of your own. The Python3 install should come with a 'pyvenv' command. For Examplebash> pyvenv mypy3
bash> source mypy3/bin/activate
(mypy3) bash> python -c 'import sys; print(sys.path)'
python: Checking MySQL database connection with mysql-connector-python
First install the MySQL package
bash>pip install --allow-all-external mysql-connector-python
Now you may test the database connection with this Python code
from mysql.connector import connect
conn = connect(user='dev', password='dev123', database='mysql')
cur = conn.cursor()
cur.execute('select 1+1')
for row in cur:
print(row)
bash>pip install --allow-all-external mysql-connector-python
Now you may test the database connection with this Python code
from mysql.connector import connect
conn = connect(user='dev', password='dev123', database='mysql')
cur = conn.cursor()
cur.execute('select 1+1')
for row in cur:
print(row)
Monday, October 5, 2015
WLS provisioning: Setup MySQL DataSource
Here is a WLST script to setup MySQL DataSource in WebLogic server after you have created a domain. The script will also assign this DataSource to one or more servers you pass in at the end of arguments.
# Update an existing domain to setup a DataSource and assign it to servers
# Example
# wlst.cmd setupDataSource.py C:\data\wls11g_domains\dev MYTESTDB jdbc/MYTESTDB com.mysql.jdbc.Driver jdbc:mysql://localhost/mytestdb test test123 AdminServer
import os, sys, os.path
(domain_home, ds_name, jndi_name, driver_name, url, user, password) = sys.argv[1:8]
servers = sys.argv[8:]
domain_home = os.path.abspath(domain_home)
readDomain(domain_home)
print("Setting up WLS DataSource: %s" % ds_name)
create(ds_name, 'JDBCSystemResource')
cd('/JDBCSystemResource/%s/JdbcResource/%s' %(ds_name, ds_name))
create('myJdbcDriverParams','JDBCDriverParams')
cd('JDBCDriverParams/NO_NAME_0')
set('DriverName',driver_name)
set('URL', url)
set('PasswordEncrypted', password)
set('UseXADataSourceInterface', 'false')
create('myProps','Properties')
cd('Properties/NO_NAME_0')
create('user', 'Property')
create('characterEncoding', 'Property')
create('connectionCollation', 'Property')
create('useUnicode', 'Property')
cd('Property/user')
cmo.setValue(user)
cd('../characterEncoding')
cmo.setValue('utf-8')
cd('../connectionCollation')
cmo.setValue('utf8_general_ci')
cd('../useUnicode')
cmo.setValue('true')
cd('/JDBCSystemResource/%s/JdbcResource/%s' %(ds_name, ds_name))
create('myJdbcDataSourceParams','JDBCDataSourceParams')
cd('JDBCDataSourceParams/NO_NAME_0')
set('JNDIName', java.lang.String(jndi_name))
cd('/')
for server in servers:
print("Assigning DS to server: %s" % server)
assign('JDBCSystemResource', ds_name, 'Target', server)
updateDomain()
exit()
# Update an existing domain to setup a DataSource and assign it to servers
# Example
# wlst.cmd setupDataSource.py C:\data\wls11g_domains\dev MYTESTDB jdbc/MYTESTDB com.mysql.jdbc.Driver jdbc:mysql://localhost/mytestdb test test123 AdminServer
import os, sys, os.path
(domain_home, ds_name, jndi_name, driver_name, url, user, password) = sys.argv[1:8]
servers = sys.argv[8:]
domain_home = os.path.abspath(domain_home)
readDomain(domain_home)
print("Setting up WLS DataSource: %s" % ds_name)
create(ds_name, 'JDBCSystemResource')
cd('/JDBCSystemResource/%s/JdbcResource/%s' %(ds_name, ds_name))
create('myJdbcDriverParams','JDBCDriverParams')
cd('JDBCDriverParams/NO_NAME_0')
set('DriverName',driver_name)
set('URL', url)
set('PasswordEncrypted', password)
set('UseXADataSourceInterface', 'false')
create('myProps','Properties')
cd('Properties/NO_NAME_0')
create('user', 'Property')
create('characterEncoding', 'Property')
create('connectionCollation', 'Property')
create('useUnicode', 'Property')
cd('Property/user')
cmo.setValue(user)
cd('../characterEncoding')
cmo.setValue('utf-8')
cd('../connectionCollation')
cmo.setValue('utf8_general_ci')
cd('../useUnicode')
cmo.setValue('true')
cd('/JDBCSystemResource/%s/JdbcResource/%s' %(ds_name, ds_name))
create('myJdbcDataSourceParams','JDBCDataSourceParams')
cd('JDBCDataSourceParams/NO_NAME_0')
set('JNDIName', java.lang.String(jndi_name))
cd('/')
for server in servers:
print("Assigning DS to server: %s" % server)
assign('JDBCSystemResource', ds_name, 'Target', server)
updateDomain()
exit()
Saturday, October 3, 2015
WLS provisioning: Creating new WebLogic domain using WLST script
Here is how to creating new WebLogic domain using WLST script without starting up a WebLogic server instance. The default AdminServer console login username is 'weblogic', and the script allow you to change its password and a port number for the AdminServer instance.
# Usage: wlst.cmd createDomain.py <domain_home> <port> <password>
# Example:
# cd D:\apps\wls1036_dev\wlserver\common\bin
# wlst.cmd scripts\createDomain.py C:\data\wls11g_domains\dev 7001 weblogic1
import os, sys, os.path
domain_home, port_s, password = sys.argv[1:]
port = int(port_s)
domain_home = os.path.abspath(domain_home)
domain_name = os.path.basename(os.path.normpath(domain_home))
template = "%s/wlserver/common/templates/domains/wls.jar" % os.environ['MW_HOME']
print("Creating WLS domain: %s" % domain_name)
# MW_HOME should be auto set by wlst.cmd script
readTemplate(template)
# Set domain name
set('Name', domain_name)
# Set AdminServer port
cd('Servers/AdminServer')
set('ListenAddress','')
set('ListenPort', port)
# Set weblogic password
cd('/Security/%s/User/weblogic' % domain_name)
cmo.setPassword(password)
# Write domain
#setOption('OverwriteDomain', 'true')
writeDomain(domain_home)
closeTemplate()
exit()
# Usage: wlst.cmd createDomain.py <domain_home> <port> <password>
# Example:
# cd D:\apps\wls1036_dev\wlserver\common\bin
# wlst.cmd scripts\createDomain.py C:\data\wls11g_domains\dev 7001 weblogic1
import os, sys, os.path
domain_home, port_s, password = sys.argv[1:]
port = int(port_s)
domain_home = os.path.abspath(domain_home)
domain_name = os.path.basename(os.path.normpath(domain_home))
template = "%s/wlserver/common/templates/domains/wls.jar" % os.environ['MW_HOME']
print("Creating WLS domain: %s" % domain_name)
# MW_HOME should be auto set by wlst.cmd script
readTemplate(template)
# Set domain name
set('Name', domain_name)
# Set AdminServer port
cd('Servers/AdminServer')
set('ListenAddress','')
set('ListenPort', port)
# Set weblogic password
cd('/Security/%s/User/weblogic' % domain_name)
cmo.setPassword(password)
# Write domain
#setOption('OverwriteDomain', 'true')
writeDomain(domain_home)
closeTemplate()
exit()
Saturday, September 26, 2015
Create simple WLS domain using WLST and built-in template jar
You can easily start up a WebLogic Server on an empty directory and it will create a domain. Here is another way to create WLS domain structure folder without actually starting up a WLS server.
# Usage: wlst.cmd createDomain.py <domain_home> <port> <password>
# NOTE: the <domain_home> must be a absolute path.
# Example: C:\wls12130\wlserver\common\bin\wlst.cmd scripts\createDomain.py C:\data\wls12c_domains\dev 7001 weblogic1
import os, sys
domain_home = sys.argv[1]
domain_name = 'mydomain'
domain_name = 'mydomain'
port = int(sys.argv[2])
password = sys.argv[3]
readTemplate(os.environ['MW_HOME'] + "/wlserver/common/templates/wls/wls.jar")
cd('/Server/AdminServer')
set('Name', domain_name + '-admin')
set('ListenAddress','')
set('ListenPort', port)
cd('/Security/base_domain/User/weblogic')
cmo.setPassword(password)
cd('/')
set('Name', domain_name)
writeDomain(domain_home)
closeTemplate()
exit()
Subscribe to:
Posts (Atom)