Wednesday, November 9, 2011

web2py - add a foreign key to aut_user

I'm still doing my project in web2py, and I wanted to add a foreign key in my auth_user table.

Problem: in the file models/, you first declare the tables auth_* and then the other tables. So if you add your foreign key you'll get an error because the "foreign table" doesn't exist yet.
Example :

auth = Auth(db)
auth.settings.extra_fields['auth_user'] = [Field('myFK', db.foreignTable)]

db.define_table('foreignTable',Field('name', length=45) )

So I tried to define my foreignTable before settings.extra_fields, but it didn't work either...

Solution :
The only solution I could find was the following :
auth = Auth(db)
auth.settings.extra_fields['auth_user'] = [Field('myFK', integer)]

db.define_table('foreignTable', Field('name', length=45) )

db.auth_user.myFK.requires = IS_IN_DB(db, '', '%(name)s', zero=T('choose one')) 
At first I declare my column as an integer, and after I define my foreignTable. Then I link myFK to my foreignTable.

And that's it!

Friday, October 14, 2011

How to install web2py on a shared host

I'm working on a project with a friend using web2py
Free open source full-stack framework for rapid development of fast, scalable, secure and portable database-driven web-based applications. Written and programmable in Python.
Official website

Now that we are ready to upload our website, we were looking for good shared host. It was not easy to find a good one. Finally we choose Site5 because it supports Python and the server is in Montreal.

how to install web2py on a shared host ?

I could find this website : web2py on shared hosting.
I followed the instructions from "Installing web2py".

When you do this, here is the url to see your app :

But what we wanted was something like that :

So here are the modifications :
- move all the web2py files directly to "public_html".
Before : $HOME/public_html/web2py/
After : $HOME/public_html/
(it's just an example with file, but you should move all the files!)

- edit $HOME/public_html/, your file should just contains :
routers = dict(
    BASE = dict(
  domains={'' : 'mySuperApp'},
*routers is a new feature of web2py. This parameter-based system first appeared in web2py version 1.92.1.
If you want to know which version of web2py you're using, just open the file $HOME/public_html/VERSION
And that's it ! Now you can access your application simply by using : !

Friday, July 29, 2011

Adding Syntax Highlighting to Blogger

How to add syntax highlighting to Blogger ?

I couldn't find a better way than this website :
That helped me a lot !

Android Mini Collectibles

*2011-08-09 The figures that I'm talking about are fake! Please read the comments

Today I'm not going to talk about software problem.
I want to talk about the Android Mini figures. I bought some and I'm not totally satisfied by the finishing.
Of course if you look at the official website (Dyzplastic) it looks very nice. And I think 80% of the time it is nice.
But here are some "bugs" that I could see.

1) Head
As you can see on the picture, there are 2 Reactor, but the one on the left has some strange stain on his head.

2) Paint
This looks like the painting was not done correctly

3) Dirty
This other Albino looks dirty (not as white as the other one)

4) Glue
The box opened by itself from the bottom. Cheap quality glue...

Well, the price of these figures is cheap but I was expecting something better from Google.

Saturday, June 11, 2011

Yii - Right join

I wanted to learn something new so I decided to create a website using the framework Yii (more info). It's written in PHP and I think it's pretty cool.

Yii comes with rich features: MVC, DAO/ActiveRecord, I18N/L10N, caching, authentication and role-based access control, scaffolding, testing, etc. It can reduce your development time significantly.

But I'm having a problem that I can't solve right now.


I have 2 tables :
- tbl_prono (id, game_id, ...) : there are 2 rows of data
- tbl_game (id, date, team_id,...) : there are 3 rows of data

In my model Prono I did the following relation:
return array(
'game'=>array(self::BELONGS_TO, 'Game', 'game_id'),

I created the following dataprovider in an action (PronoController):

$dataProvider=new CActiveDataProvider('Prono', array(
'with'=>array('game'=>array('joinType'=>'RIGHT JOIN')),
// please note the RIGHT JOIN


It generates a correct sql querry. But it returns 2 rows instead of 3 !
It should return 3 rows because I'm doing a "right join" and tbl_game has 3 rows.

So, in my CgridView, I can see only 2 rows...

I couldn't find a solution to display 3 rows....

Thursday, April 14, 2011

ORA-01940 cannot drop user

Oracle 10g, I want to drop a user using this command :
drop user alex cascade;

But I have this error:
ORA-01940: cannot drop a user that is currently logged in

Solution :
I checked on google and find this excellent Website :
It said that you should do this :

select s.sid, s.serial#, s.status, p.spid
from v$session s, v$process p
where s.username = 'myuser'
and p.addr (+) = s.paddr;

alter system kill session 'sid,serial#';

That's correct but your username should be in uppercase!
For example :
where s.username = 'ALEX'

And that's it !

You can do a quick test :

select username from v$session;
select * from v$session where username = 'alex';
select * from v$session where username = 'ALEX';

Wednesday, April 13, 2011

path oracle 10g

You can't execute commands such as "imp", "exp", "impdp" or "expdp" even though the path is setted in the environment variable.

In my case, there was a mistake. When I installed Oracle 10g, the path was automatically set to :

But in reality it should be "BIN" (uppercase)!

After modifying the path, I could execute the command "impdp" anywhere from the command line.

Sunday, February 20, 2011

SQLiteDatabase created and never closed

When I'm using my application and I can see this error in the LogCat tab :

02-17 17:20:38.556: ERROR/Database(434): Leak found
02-17 17:20:38.556: ERROR/Database(434): java.lang.IllegalStateException: /data/data/databases/xx.db SQLiteDatabase created and never closed

Well, at first I thought it was because of my cursors. So I decided to check every cursor and close them all after having done with them.
But I still got the same problem.

So in fact, it's just that for every activity (onCreate) I was opening a connection to the database, but I never closed it.
So the solution was to close the connection in each activity:

protected void onStop() {

And that's it !

Sunday, February 13, 2011

Android Insufficient storage

I was debugging my application using an android virtual device in Eclipse.
When I run the application I could see this error in the console:

[2011-02-12 19:22:25 - shiro] Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE
[2011-02-12 19:22:25 - shiro] Please check logcat output for more details.
[2011-02-12 19:22:25 - shiro] Launch canceled!

The size of my app is around 22Mo (there are a lot of pictures).

The first time I configured the android virtual device, I put only 2 or 3Mo for "SD Card size".
So I had no choice to create a new virtual device and put something like 30Mo.
I ran my app for the first time. No problem. Then I wanted to run it again, and I got the same problem. I guess I could set the size of SD card to 100Mo, or in the virtual device, you can go to the menu > settings > manage applications. Then choose the application and uninstall it. Then you can run your app again in debug mode from Eclipse.

And that's it!