[sqlalchemy] Re: creating tables dynamically

2010-07-23 Thread Aref
Thank you for taking the time to reply.
The application I am writing takes input from the user to define the
table name, number of columns, types etc... I tried formatting the
inputs in a list and then passing the list elements to Table(). I kept
getting error messages. I abandoned this approach and simply used
basic SQL expression to get this done. It works.
Again thank you for the response.

On Jul 23, 3:47 am, Nebur g...@reifenberg.de wrote:
 That shouldn't be too hard...
 When creating a Table as shown in the tutorial, you can provide any
 number of columns.
 You can later modify an existing Table object; there's an
 append_column method. 
 See:http://www.sqlalchemy.org/docs/reference/sqlalchemy/schema.html#table...
  Nebur

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] creating tables dynamically

2010-07-22 Thread Aref
Hello,

I am working on an application where I would need to create a table in
a database but I do not have a priori knowledge of how many columns
does this table has. Is it possible to do this in SA? If so can
someone point me to an example or reference documentation explaining
how to accomplish this?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: modifying a field

2010-06-22 Thread Aref
In this example I used:
DB.password = 'hello'  where passwod is the column name. Can I pass
the column name in a variable? It does not seem that I could. I have
tried different ways but none seems to work.
Thanks.

On Jun 20, 5:18 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 On Jun 20, 2010, at 5:53 PM, Aref wrote:



  db = SqlSoup('sqlite:///c:\\tutorial.db3')
  db_dynamic = 'tf_user'
  DB = db.entity(db_dynamic)
  print DB
  ColHeader = DB.c.keys()
  conn = db.connection()
  #modify a field
  DB.password = 'hello'
  db.flush()

 It appears you're using a method called entity(), which would return a handle 
 to the current table called tf_user in this case.   To modify a row, you 
 need to load the row first.     You do this with filter(), first(), one(), 
 etc.   It seems here you're tacking on the word hello to the query object 
 itself which would have no effect.   Examples of loading actual rows 
 athttp://www.sqlalchemy.org/docs/reference/ext/sqlsoup.html?highlight=s   
 The tutorial here seems to use the special variable _, which is unfortunate 
 (I didn't write any of this), but it implies the row that was previously 
 loaded via one().  thats the thing you change.      



  #get the table data
  data = select([db.tf_user],)
  listdata=[]
  for row in conn.execute(data):
      row = [%s % el for el in row]
      listdata.append(row)
  print listdata

  which is supposed to modify the value of the password field in a 
  database to 'hello'. However, when I examine the database nothing has 
  changed, the old value is still there. What am I doing wrong? What is 
  the best way to update or modify fields? I can't seem to find anything 
  substantial regarding SQLSoup.

  you need to commit() the transaction.    The current 0.6 docs describe 
  this:http://www.sqlalchemy.org/docs/reference/ext/sqlsoup.html?highlight=s...quoted
   text -

  - Show quoted text -

  --
  You received this message because you are subscribed to the Google Groups 
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to 
  sqlalchemy+unsubscr...@googlegroups.com.
  For more options, visit this group 
  athttp://groups.google.com/group/sqlalchemy?hl=en.-Hide quoted text -

  - Show quoted text -

  --
  You received this message because you are subscribed to the Google Groups 
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to 
  sqlalchemy+unsubscr...@googlegroups.com.
  For more options, visit this group 
  athttp://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: modifying a field

2010-06-21 Thread Aref
Thank you so much. That worked. I was staring at the SQLsoup doc you
linked to for hours trying to understand but could not figure what the
_ meant. In any case your explanation is clear and very useful.
Thanks again.

On Jun 20, 5:18 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 On Jun 20, 2010, at 5:53 PM, Aref wrote:



  db = SqlSoup('sqlite:///c:\\tutorial.db3')
  db_dynamic = 'tf_user'
  DB = db.entity(db_dynamic)
  print DB
  ColHeader = DB.c.keys()
  conn = db.connection()
  #modify a field
  DB.password = 'hello'
  db.flush()

 It appears you're using a method called entity(), which would return a handle 
 to the current table called tf_user in this case.   To modify a row, you 
 need to load the row first.     You do this with filter(), first(), one(), 
 etc.   It seems here you're tacking on the word hello to the query object 
 itself which would have no effect.   Examples of loading actual rows 
 athttp://www.sqlalchemy.org/docs/reference/ext/sqlsoup.html?highlight=s   
 The tutorial here seems to use the special variable _, which is unfortunate 
 (I didn't write any of this), but it implies the row that was previously 
 loaded via one().  thats the thing you change.      





  #get the table data
  data = select([db.tf_user],)
  listdata=[]
  for row in conn.execute(data):
      row = [%s % el for el in row]
      listdata.append(row)
  print listdata

  which is supposed to modify the value of the password field in a 
  database to 'hello'. However, when I examine the database nothing has 
  changed, the old value is still there. What am I doing wrong? What is 
  the best way to update or modify fields? I can't seem to find anything 
  substantial regarding SQLSoup.

  you need to commit() the transaction.    The current 0.6 docs describe 
  this:http://www.sqlalchemy.org/docs/reference/ext/sqlsoup.html?highlight=s...quoted
   text -

  - Show quoted text -

  --
  You received this message because you are subscribed to the Google Groups 
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to 
  sqlalchemy+unsubscr...@googlegroups.com.
  For more options, visit this group 
  athttp://groups.google.com/group/sqlalchemy?hl=en.-Hide quoted text -

  - Show quoted text -

  --
  You received this message because you are subscribed to the Google Groups 
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to 
  sqlalchemy+unsubscr...@googlegroups.com.
  For more options, visit this group 
  athttp://groups.google.com/group/sqlalchemy?hl=en.- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] modifying a field

2010-06-20 Thread Aref Nammari
I have the following code:

db = SqlSoup('sqlite:///c:\\tutorial.db3')
db_dynamic = 'tf_user'
DB = db.entity(db_dynamic)
print DB
ColHeader = DB.c.keys()
conn = db.connection()
#modify a field
DB.password = 'hello'
db.flush()

#get the table data
data = select([db.tf_user],)
listdata=[]
for row in conn.execute(data):
row = [%s % el for el in row]
listdata.append(row)
print listdata

which is supposed to modify the value of the password field in a database to
'hello'. However, when I examine the database nothing has changed, the old
value is still there. What am I doing wrong? What is the best way to update
or modify fields? I can't seem to find anything substantial regarding
SQLSoup.


Thanks
Aref

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: modifying a field

2010-06-20 Thread Aref
yes the field password is an actual column. Below is the table
definition:

from sqlalchemy import *
from datetime import datetime
metadata = MetaData('sqlite:///c:\\tutorial.db3')
user_table = Table(\
'tf_user', metadata,
Column('id', Integer, primary_key=True),
Column('user_name', Unicode(16), \
unique= True, nullable=False),
Column('password', Unicode(40), nullable=False),
Column('display_name', Unicode(255), default=''),
Column('created', DateTime, default=datetime.now))

If I put a print statement in the code to print the field (before the
flush and commit) it prints the right value but that does not make it
to the file for some reason. I will try your suggection and see.
Thanks.

On Jun 20, 3:40 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 On Jun 20, 2010, at 5:33 PM, Aref wrote:

  I tried that and still cannot seem to change the field.

 is password an actual column in the database table ?   create a SQLSoup 
 using an engine obtained via create_engine(), and specify echo=True on that 
 engine to see what SQL is actually emitted.





  On Jun 20, 3:25 pm, Michael Bayer mike...@zzzcomputing.com wrote:
  On Jun 20, 2010, at 5:18 PM, Aref Nammari wrote:

  I have the following code:

  db = SqlSoup('sqlite:///c:\\tutorial.db3')
  db_dynamic = 'tf_user'
  DB = db.entity(db_dynamic)
  print DB
  ColHeader = DB.c.keys()
  conn = db.connection()
  #modify a field
  DB.password = 'hello'
  db.flush()

  #get the table data
  data = select([db.tf_user],)
  listdata=[]
  for row in conn.execute(data):
      row = [%s % el for el in row]
      listdata.append(row)
  print listdata

  which is supposed to modify the value of the password field in a database 
  to 'hello'. However, when I examine the database nothing has changed, the 
  old value is still there. What am I doing wrong? What is the best way to 
  update or modify fields? I can't seem to find anything substantial 
  regarding SQLSoup.

  you need to commit() the transaction.    The current 0.6 docs describe 
  this:http://www.sqlalchemy.org/docs/reference/ext/sqlsoup.html?highlight=s...Hide
   quoted text -

  - Show quoted text -

  --
  You received this message because you are subscribed to the Google Groups 
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to 
  sqlalchemy+unsubscr...@googlegroups.com.
  For more options, visit this group 
  athttp://groups.google.com/group/sqlalchemy?hl=en.- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: modifying a field

2010-06-20 Thread Aref
Here is the echoed info when the code is run:


2010-06-20 16:00:02,546 INFO sqlalchemy.engine.base.Engine.0x...6c50
PRAGMA table_info(tf_user)
2010-06-20 16:00:02,546 INFO sqlalchemy.engine.base.Engine.0x...6c50
()
2010-06-20 16:00:02,546 INFO sqlalchemy.engine.base.Engine.0x...6c50
PRAGMA foreign_key_list(tf_user)
2010-06-20 16:00:02,546 INFO sqlalchemy.engine.base.Engine.0x...6c50
()
2010-06-20 16:00:02,546 INFO sqlalchemy.engine.base.Engine.0x...6c50
PRAGMA index_list(tf_user)
2010-06-20 16:00:02,546 INFO sqlalchemy.engine.base.Engine.0x...6c50
()
class 'sqlalchemy.ext.sqlsoup.MappedTf_user'
2010-06-20 16:00:02,546 INFO sqlalchemy.engine.base.Engine.0x...6c50
BEGIN
2010-06-20 16:00:02,546 INFO sqlalchemy.engine.base.Engine.0x...6c50
COMMIT
2010-06-20 16:00:02,546 INFO sqlalchemy.engine.base.Engine.0x...6c50
BEGIN
2010-06-20 16:00:02,546 INFO sqlalchemy.engine.base.Engine.0x...6c50
SELECT tf_user.id, tf_user.user_name, tf_user.password,
tf_user.display_name, tf_user.created
FROM tf_user
2010-06-20 16:00:02,546 INFO sqlalchemy.engine.base.Engine.0x...6c50
()
[['1', u'Joey', u'top-Secret', u'plummer', '2010-06-19
20:35:27.093000']]



On Jun 20, 3:40 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 On Jun 20, 2010, at 5:33 PM, Aref wrote:

  I tried that and still cannot seem to change the field.

 is password an actual column in the database table ?   create a SQLSoup 
 using an engine obtained via create_engine(), and specify echo=True on that 
 engine to see what SQL is actually emitted.





  On Jun 20, 3:25 pm, Michael Bayer mike...@zzzcomputing.com wrote:
  On Jun 20, 2010, at 5:18 PM, Aref Nammari wrote:

  I have the following code:

  db = SqlSoup('sqlite:///c:\\tutorial.db3')
  db_dynamic = 'tf_user'
  DB = db.entity(db_dynamic)
  print DB
  ColHeader = DB.c.keys()
  conn = db.connection()
  #modify a field
  DB.password = 'hello'
  db.flush()

  #get the table data
  data = select([db.tf_user],)
  listdata=[]
  for row in conn.execute(data):
      row = [%s % el for el in row]
      listdata.append(row)
  print listdata

  which is supposed to modify the value of the password field in a database 
  to 'hello'. However, when I examine the database nothing has changed, the 
  old value is still there. What am I doing wrong? What is the best way to 
  update or modify fields? I can't seem to find anything substantial 
  regarding SQLSoup.

  you need to commit() the transaction.    The current 0.6 docs describe 
  this:http://www.sqlalchemy.org/docs/reference/ext/sqlsoup.html?highlight=s...Hide
   quoted text -

  - Show quoted text -

  --
  You received this message because you are subscribed to the Google Groups 
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to 
  sqlalchemy+unsubscr...@googlegroups.com.
  For more options, visit this group 
  athttp://groups.google.com/group/sqlalchemy?hl=en.- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] session save

2010-06-16 Thread Aref
Hello,
I am learning sqlalchemy and been reading and working through the
examples/tutorials in Copeland's Essential SQLAlchemy.
I am running sqlalchemy 0.6.1 and python2.5
I am running into a problem when trying to save a session using save.

session.save(newuser)

for example. I get an error saying that 'Session' has no attribute
'save'.

I amde sure that the module sqlachemy.orm is imported. Is this
attribute really missing, has it been replaced or is there anything
that I am missing?
Thanks in advance for any insight that you can offer.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: session save

2010-06-16 Thread Aref
Thank you so much. I'll make a note of that.

On Jun 16, 7:35 am, Michael Bayer mike...@zzzcomputing.com wrote:
 unfortunately Essential SQLA is sorely out of date, save() was moved to add() 
 around the time of late 0.4 and in 0.6 we've removed the old save().

 On Jun 16, 2010, at 9:31 AM, Aref wrote:



  Hello,
  I am learning sqlalchemy and been reading and working through the
  examples/tutorials in Copeland's Essential SQLAlchemy.
  I am running sqlalchemy 0.6.1 and python2.5
  I am running into a problem when trying to save a session using save.

  session.save(newuser)

  for example. I get an error saying that 'Session' has no attribute
  'save'.

  I amde sure that the module sqlachemy.orm is imported. Is this
  attribute really missing, has it been replaced or is there anything
  that I am missing?
  Thanks in advance for any insight that you can offer.

  --
  You received this message because you are subscribed to the Google Groups 
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to 
  sqlalchemy+unsubscr...@googlegroups.com.
  For more options, visit this group 
  athttp://groups.google.com/group/sqlalchemy?hl=en.- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: session save

2010-06-16 Thread Aref
Is there a book that is more current that you recommend?

Thanks

On Jun 16, 7:35 am, Michael Bayer mike...@zzzcomputing.com wrote:
 unfortunately Essential SQLA is sorely out of date, save() was moved to add() 
 around the time of late 0.4 and in 0.6 we've removed the old save().

 On Jun 16, 2010, at 9:31 AM, Aref wrote:



  Hello,
  I am learning sqlalchemy and been reading and working through the
  examples/tutorials in Copeland's Essential SQLAlchemy.
  I am running sqlalchemy 0.6.1 and python2.5
  I am running into a problem when trying to save a session using save.

  session.save(newuser)

  for example. I get an error saying that 'Session' has no attribute
  'save'.

  I amde sure that the module sqlachemy.orm is imported. Is this
  attribute really missing, has it been replaced or is there anything
  that I am missing?
  Thanks in advance for any insight that you can offer.

  --
  You received this message because you are subscribed to the Google Groups 
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to 
  sqlalchemy+unsubscr...@googlegroups.com.
  For more options, visit this group 
  athttp://groups.google.com/group/sqlalchemy?hl=en.- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] help please

2010-06-10 Thread Aref
Hello All,

I just began learning sqlalchemy and am not quite used to it yet so
please excuse my ignorance and which might be a trivial question to
some of you.
I am writing a database module and need to load a table and possibly
modify a record in the table. I can get the connection established and
everything works fine. The problem I am running into is that I do not
necessarily know the column name before hand to code it in the update
method. I want to be able to find out to send a generic column name
which will be updated (gets the column name dynamically).

I tried the following:

columns=['ProjectID', 'Program', 'progmanger']
test = str('table.c.'+columns[1])
update = table.update(test=='project-name', values = {test:'program'})
print update
update.execute()

I get a error when I try to run it. It does not recognize the column
for some reason even though if I print test everything seems to be OK.
I get 'project.c.Program'

Is there something I am missing here? How can I send the project and
column name to the update method dynamically?

Thank you so much in advance for any help or insight you could provide.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: help please

2010-06-10 Thread Aref
Thank you for the response. However, that is not the problem. If I do

update = table.update(project.c.ProjectID=='project-name', values =
{project.c.ProjectID:'program'})
print update
update.execute()

everything works fine.
if I do this:

test = 'table.c.'+columns[0] #columns is a list which contains the
columns names
update = table.update(test == 'project-name', values={test:'program'})
update.execute()

it does not work. I get an error that there is no such column.
I need to be able to update columns dynamically where I do not have a
prior knowledge of what tables and what are the table columns that may
exist. How can I do that if at all?

On Jun 10, 7:21 am, GHZ geraint.willi...@gmail.com wrote:
 you should access column names via lower case

 i.e.

 columns = 'projectid', 'program', 'progmanger']

 On 10 Jun, 03:39, Aref arefnamm...@gmail.com wrote:



  Hello All,

  I just began learning sqlalchemy and am not quite used to it yet so
  please excuse my ignorance and which might be a trivial question to
  some of you.
  I am writing a database module and need to load a table and possibly
  modify a record in the table. I can get the connection established and
  everything works fine. The problem I am running into is that I do not
  necessarily know the column name before hand to code it in the update
  method. I want to be able to find out to send a generic column name
  which will be updated (gets the column name dynamically).

  I tried the following:

  columns=['ProjectID', 'Program', 'progmanger']
  test = str('table.c.'+columns[1])
  update = table.update(test=='project-name', values = {test:'program'})
  print update
  update.execute()

  I get a error when I try to run it. It does not recognize the column
  for some reason even though if I print test everything seems to be OK.
  I get 'project.c.Program'

  Is there something I am missing here? How can I send the project and
  column name to the update method dynamically?

  Thank you so much in advance for any help or insight you could provide.- 
  Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: help please

2010-06-10 Thread Aref
Thank you very much. I'll try it. Is there a better way of doing this--
I mean there must be since this is necessary for any application
needing to modify a database where generally tables are accessed
dynamically.

On Jun 10, 9:37 am, Lance Edgar lance.ed...@gmail.com wrote:
 On 6/10/2010 10:29 AM, Aref wrote:Thank you for the response. However, that 
 is not the problem. If I do update = 
 table.update(project.c.ProjectID=='project-name', values = 
 {project.c.ProjectID:'program'}) print update update.execute() everything 
 works fine. if I do this: test = 'table.c.'+columns[0] #columns is a list 
 which contains the columns names update = table.update(test == 
 'project-name', values={test:'program'}) update.execute() it does not work. I 
 get an error that there is no such column. I need to be able to update 
 columns dynamically where I do not have a prior knowledge of what tables and 
 what are the table columns that may exist. How can I do that if at all?
 Instead try:update = table.update(eval(test)=='project-name', 
 values={test:'program'})I can't say for sure that's the best way to do it 
 still, but it would solve your immediate problem.  The test variable is 
 referencing a string, not a column.  You have to eval() it to get the column 
 reference.
 However, you say your error is that there is no such column ... I'd expect 
 a much different error if my suggestion were to actually fix your problem.  
 Anyway good luck. :)  Might include your traceback next time if you still 
 have problems.
 Lance

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.