FUTURE LOGIC INC.
on T3

This section covers the Data Access Layer (DAL)

request:
application
:
init
args
:
DAL
body
:
<cStringIO.StringO object at 0x196fa626fd56ac40>
client
:
38.107.191.99
controller
:
default
cookies
:
session_id_init
:
comment
:
domain
:
expires
:
max-age
:
path
:
secure
:
version
:
env
:
application_id
:
futurelogic1
auth_domain
:
gmail.com
current_version_id
:
1.336480981840486266
datacenter
:
na1
googlebase
:
/base/python_lib/versions/1
http_accept
:
text/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
http_accept_charset
:
ISO-8859-1,utf-8;q=0.7,*;q=0.7
http_accept_language
:
en-us,en;q=0.5
http_cache_control
:
no-cache
http_cookie
:
session_id_init="246001:56ab7d1a-9969-4ba7-83d2-55a8351fc1ab"
http_host
:
www.futurelogic.com
http_pragma
:
no-cache
http_user_agent
:
CCBot/1.0 (+http://www.commoncrawl.org/bot.html),gzip(gfe),gzip(gfe)
http_x_cc_id
:
ccc01-02
http_x_google_apps_metadata
:
domain=futurelogic.com
https
:
off
path_info
:
/init/default/wiki/DAL
path_translated
:
/base/data/home/apps/futurelogic1/1.336480981840486266/gaehandler.py
query_string
:
remote_addr
:
38.107.191.99
request_method
:
GET
script_name
:
server_name
:
www.futurelogic.com
server_port
:
80
server_protocol
:
HTTP/1.1
server_software
:
Google App Engine/1.3.1
tz
:
UTC
user
:
apphosting
user_email
:
user_id
:
user_is_admin
:
0
user_nickname
:
user_organization
:
web2py_path
:
/base/data/home/apps/futurelogic1/1.336480981840486266
web2py_runtime
:
gae:production
web2py_runtime_gae
:
True
web2py_version
:
Version 1.62.3 (2009-05-19 23:25:03)
wsgi_errors
:
<cStringIO.StringO object at 0x196fa626ff84bd30>
wsgi_file_wrapper
:
<class wsgiref.util.FileWrapper at 0x196fa626ff3184c8>
wsgi_input
:
<cStringIO.StringI object at 0x196fa626fd697188>
wsgi_multiprocess
:
True
wsgi_multithread
:
False
wsgi_run_once
:
True
wsgi_url_scheme
:
http
wsgi_version
:
1
0
folder
:
/base/data/home/apps/futurelogic1/1.336480981840486266/applications/init/
function
:
wiki
get_vars
:
now
:
datetime.datetime(2010, 3, 11, 5, 58, 1, 951801)
post_vars
:
vars
:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
session:
errors
:
flash
:
None
t2
:
my_groups_id
:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
response:
author
:
David Lypka
body
:
<cStringIO.StringO object at 0x196fa626fd0d6af8>
cookies
:
session_id_init
:
comment
:
domain
:
expires
:
max-age
:
path
:
/
secure
:
version
:
description
:
None
files
:
/plugin_t2/static/t2/scripts/jquery.js
/plugin_t2/static/t2/styles/calendar.css
/plugin_t2/static/t2/scripts/calendar.js
/plugin_t2/static/t2/styles/sfmenu.css
/plugin_t2/static/t2/scripts/sfmenu.js
/plugin_t2/static/t2/scripts/fancyzoom.min.js
/plugin_t2/static/t2/styles/rating.css
/plugin_t2/static/t2/scripts/rating.js
flash
:
None
headers
:
Cache-Control
:
no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires
:
Thu, 11 Mar 2010 05:58:01 GMT
Pragma
:
no-cache
keywords
:
web2py python google app engine GAE ORM
menu
:
Currents
False
/init/default/wiki/Currents
futurelogic on T3
False
/init/default/wiki/main
web2py
False
/init/default/wiki/web2py
Forum Extracts
False
/init/default/wiki/extracts
CRUD
False
/init/default/wiki/CRUD
DAL
True
/init/default/wiki/DAL
Excel
False
/init/default/wiki/Excel
Forms
False
/init/default/wiki/Forms
auth
False
/init/default/wiki/auth
imaging
False
/init/default/wiki/imaging
memcache
False
/init/default/wiki/memcache
translation
False
/init/default/wiki/translation
on GAE
False
/init/default/wiki/web2pyOnGAE
DALnr
False
/init/default/wiki/DALnr
Deploying
False
/init/default/wiki/GAEDeploy
postprocessing
:
session_filename
:
/base/data/home/apps/futurelogic1/1.336480981840486266/applications/init/sessions/38-107-191-99-962fc225-6d4e-4275-a2c0-49dbe4f56781
session_id
:
246001:56ab7d1a-9969-4ba7-83d2-55a8351fc1ab
session_id_name
:
session_id_init
session_new
:
True
status
:
200
subtitle
:
on T3
title
:
FUTURE LOGIC INC.
view
:
default/wiki.html
==========================================================================
From http://groups.google.com/group/web2py/browse_thread/thread/3654863ae1de26a1

, I would define tables

as usual only to get an SQL error saying the table exists.

 

 

From: mdipierro < mdipie...@cs.depaul.edu >

Date: Mon, 4 May 2009 07:23:39 -0700 (PDT)

Local: Mon, May 4 2009 10:23 am

Subject: Re: Table already exists problem [again]

 

This is complex. Currently the way to avoid the problem is to name

the .table files via

 

db.define_table('something',.. ..,migrate='something.table')

 

 

using "IF EXISTS" would only solve this problem to create others.

 

 

Massimo

 

 

From: mdipierro < mdipie...@cs.depaul.edu >

Date: Mon, 4 May 2009 16:29:46 -0700 (PDT)

Local: Mon, May 4 2009 7:29 pm

Subject: Re: Table already exists problem [again]

 

web2py, for now, does not have the ability to query the db about which

tables are in there are stores metadata about that in .table files.

 

If we enable IF_NOT_EXISTS it means web2py is ignoring metadata

from .table file (else IF_NOT_EXISTS) would not be needed at all.

 

 

If the table exists but differs from the current model, web2py will

not be able to detect it, will not be able to migrate, and it will

just not work.

 

 

This will make apps harder to debug and data more difficult to

recover.

 

 

Right now if the table exists and you do not want migrations just set

migrate=False.

You cannot at the same time ignore .table files and have migrations.

 

 

If you learn how to manipulate .table files (by giving them names

instead of using the default names) you can fix every problem.

 

 

From: mdipierro < mdipie...@cs.depaul.edu >

Date: Tue, 5 May 2009 07:25:43 -0700 (PDT)

Local: Tues, May 5 2009 10:25 am

Subject: Re: Table already exists problem [again]

 

I am not sure what you mean by "in a way that it survives framework

updates".

 

The only problems I can see would arise if:

- You delete databases/*.table but the database is still there

(updates do not cause this). Bad luck. One should not delete files, or

at least make a backup.

- Your databases/*.table are still there but you change name or login/

password for the actual database. This is not a problem. You only need

to rename the old *.table files. By default the file names are md5

hashes of the dburi string. 

Notice that you can do

 

 

auth.define_table(migrate= False)

 

Massimo

 

  The current system does not limit

that. It only limits the fact that one app should do migrations. If

more than one app may do migrations just symlink the database folder.

 

Massimo

TW...

 

I do not think the current system is perfect. Ideally web2py should

query the database for the current table stucture instead of using

local .table files. .table files exist because

- I do not know an alternative

- because it is faster to look this up locally than query the database

 

 Massimo

  

 

NOTE by Dave Lypka:

When I did this this on remote existing SQL Server database tables, web2py worked fine.

 

try:

    from gluon.contrib.gql import *         # if running on Google App Engine

except:

    db=SQLDB('sqlite://storage.db')         # if not, use SQLite or other DB - Used by T2

    dbmssql = SQLDB('mssql://dlypka:none@localhost/TMoMilestones')

 

dbmssql.define_table('TMoProjectIdView',

                dbmssql.Field('strProjectType','string'),

                dbmssql.Field('strProjectName','string'),

                dbmssql.Field('strProjectDescription','string'),

                dbmssql.Field('dtCreated','datetime'),

                dbmssql.Field('dtLastupdate','datetime'),

                migrate=False)

 

==========================================================================

 

 

From: mdipierro < mdipie...@cs.depaul.edu >

Date: Wed, 6 May 2009 22:26:16 -0700 (PDT)

Local: Thurs, May 7 2009 1:26 am

Subject: Re: Stream a blob

 

On May 6, 10:05 pm, rbp < richar...@gmail.com > wrote: 

> hello, 

> I just noticed that web2py has an easy way to stream data - that's

> fantastic!

> Currently I upload and download data without streaming which is really

> tough on my web2py server. 

> All the examples I've seen are for streaming a file on the file

> system. Is it possible to stream a blob fieldtype without loading it

> all into memory at once? 

No because web2py base64 encodes blobs.

 

> Also, how can I manually stream an upload? I am trying to save the

> posted data with a request without the server having to load it all

> into memory at once. 

If you use SQLField('file','upload') it ill by default stream in

upload and download.

If you use SQLField ('file','upload',uploadfield=' the_blob_field') then it must be read in

memory at once in order to communicate with the DB.

 

Massimo

 

===================================================================

 

 

From http://groups.google.com/group/web2py/browse_thread/thread/3ab6a957ac96747b 
  
From: Pystar <aitoehi...@gmail.com>
Date: Wed, 6 May 2009 10:00:33 -0700 (PDT)
Local: Wed, May 6 2009 1:00 pm 
Subject: Strange Behaviour? ondelete="CASCADE"
Hi All, 
In the Web2py book, in the DAL section, one of the arguments of the 
SQLField constructor is "ondelete" and the explanation is that any 
SQLField that has the "ondelete="CASCADE" will have all referencing 
records deleted when it is deleted. 
But i have noticed that this doesnt work for me. Can anyone explain 
how the ondelete works? 
Here is an example of the code: 
db.define_table("Person", 
SQLField("name", "string", length=32, default=None, required=True, 
requires=IS_NOT_EMPTY(), ondelete="cascade") 
db.define_table("Pet", 
SQLField("pet_name', "string", lentgth=32, default=None, 
required=True), 
SQLField("pet_owner", db.Person, requires=IS_IN_DB(db, "Person.id", 
"Person.name")) 
after creating records of a pet owner and some pets, if i try deleting 
a pet owner, i would expect the records of all the pets owned by that 
"Person" to be deleted also but the records are still there. 
I would like to know if i am missing something here? Any explanation 
is welcome. 
Thanks 
Pystar. 
From: annet.verm...@gmail.com
Date: Wed, 6 May 2009 10:28:25 -0700 (PDT)
Local: Wed, May 6 2009 1:28 pm 
Subject: Re: Strange Behaviour? ondelete="CASCADE"
Reply | Reply to author | Forward | Print | Individual message | Show original | Report this message | Find messages by this author 
Hi Pystar, 
I think the ondelete='CASCADE' should be in the referencing table: 
db.define_table("Pet", 
SQLField("pet_name', "string", lentgth=32, default=None, 
required=True), 
SQLField("pet_owner", db.Person, requires=IS_IN_DB(db, "Person.id", 
"Person.name"), ondelete='CASCADE')) 
In SQL this would read like: 
CONSTRAINT pet_person_fkey FOREIGN KEY (pet_owner) 
      REFERENCES  person (id) MATCH SIMPLE 
      ON UPDATE NO ACTION ON DELETE CASCADE 
I hope this solved your problem. 
Annet 
From http://groups.google.com/group/web2py/browse_thread/thread/3ab6a957ac96747b 
  
From: Pystar <aitoehi...@gmail.com>
Date: Wed, 6 May 2009 10:00:33 -0700 (PDT)
Local: Wed, May 6 2009 1:00 pm 
Subject: Strange Behaviour? ondelete="CASCADE"
Hi All, 
In the Web2py book, in the DAL section, one of the arguments of the 
SQLField constructor is "ondelete" and the explanation is that any 
SQLField that has the "ondelete="CASCADE" will have all referencing 
records deleted when it is deleted. 
But i have noticed that this doesnt work for me. Can anyone explain 
how the ondelete works? 
Here is an example of the code: 
db.define_table("Person", 
SQLField("name", "string", length=32, default=None, required=True, requires=IS_NOT_EMPTY(), ondelete="cascade") ) 
db.define_table("Pet", 
SQLField("pet_name', "string", lentgth=32, default=None, required=True), 
SQLField("pet_owner", db.Person, requires=IS_IN_DB(db, "Person.id", "Person.name")) ) 
after creating records of a pet owner and some pets, if i try deleting 
a pet owner, i would expect the records of all the pets owned by that 
"Person" to be deleted also but the records are still there. 
I would like to know if i am missing something here? Any explanation 
is welcome. 
Thanks 
Pystar. 
From: annet.verm...@gmail.com
Date: Wed, 6 May 2009 10:28:25 -0700 (PDT)
Local: Wed, May 6 2009 1:28 pm 
Subject: Re: Strange Behaviour? ondelete="CASCADE"
Hi Pystar, 
I think the ondelete='CASCADE' should be in the referencing table: 
db.define_table("Pet", 
SQLField("pet_name', "string", lentgth=32, default=None, required=True), 
SQLField("pet_owner", db.Person, requires=IS_IN_DB(db, "Person.id", "Person.name"), ondelete='CASCADE')) 
In SQL this would read like: 
CONSTRAINT pet_person_fkey FOREIGN KEY (pet_owner) 
      REFERENCES  person (id) MATCH SIMPLE 
      ON UPDATE NO ACTION ON DELETE CASCADE 
I hope this solved your problem. 
Annet 
===============================================================================