[web2py] Re: Importing an already existing MySQL database

2014-07-03 Thread Gideon George
Please how can I use the script? I mean, where will I save the script? 
anywhere online where I can just download it instead of copy & paste?

On Wednesday, 15 July 2009 00:09:20 UTC+1, Boriel wrote:
>
> Hi,
>
> I'm rather new to web2py, but I think this script might be helpful to 
> others.
> I've created a little python script that will automatically dump on
> the screen the creation of an already existing mysql database to be
> ready to use with web2py.
>
> So, for example, if you have already created a MySQL db called
> "mybooks" and want to import it to web2py, just type:
> mysqltoweb2py.py mybooks  
>
> And it will dump on the screen the orders needed to be copied in the db.py 
> file.
> This is the script:
>
> = 8< == 8< == 8< ==
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
> '''
> mysqltoweb2py --> Import an already existing MySQL Database
> into web2py.
>
> Usage:
> mysqltoweb2py.py   
> '''
>
> import sys
> import re
> import MySQLdb
>
> reFieldType = re.compile(r'([a-zA-Z]+)([(]\d+[)])?')
> reLetter = re.compile('[a-zA-Z]')
>
>
> datab = sys.argv[1]
> user = sys.argv[2]
> passwd = sys.argv[3]
>
> db=MySQLdb.connect(host='localhost',user=user, passwd = passwd, db = datab)
>
>
> def error_msg(msg):
> ''' This could be implemented as an exception
> '''
> sys.stderr.write("%s\n" % msg)
> sys.exit(1)
>
>
> def output_table(table):
> cursor=db.cursor()
> cursor.execute('show columns from `%s`' % table)
>
> print "db.define_table('%s'," % table
> # Extract table fields
> for field in cursor.fetchall():
> if field[0] == 'id':
> continue # id field ignored
>
> if not reLetter.match(field[0][0]):
> error_msg("Error: field name [%s] in table [%s] does not
> begin with a letter" % (field[0], table))
>
> ftype = reFieldType.match(field[1])
> if not ftype:
> error_msg("Error: could not parse column type")
>
> _type, _len = tuple(ftype.groups())
> if _type == 'varchar':
> _type = 'string'
> elif _type in ('int', 'tinyint'):
> _type = 'integer'
>
> print "\tSQLField('%s'," % field[0],
> print "type = '%s'" % _type,
> if _len is not None: # Has a length?
> print ", length = %i" % int(_len[1:-1]),
> print "),"
>
> print "\tmigrate = False)"
>
>
> cursor = db.cursor()
> cursor.execute('show tables')
> for table in cursor.fetchall():
> print
> output_table(table[0])
> === 8< == 8< == 8< ==
>
> Many things to be done:
>
> 1) Fieldnames starting with "_" are not allowed by web2py (but MySQL
> allows it). An error is printed
> 2) Some field types do not exist in web2py (e.g. tinyint) so an
> equivalent is used.
>
> Regards,
> J.
>
> -- 
> Boriel  http://www.boriel.com
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Importing an already existing MySQL database

2011-02-17 Thread Rupesh Pradhan

Okay, I found it.
The .py file was in the src version of web2py.
Anyway, the script is giving the following error, whereas the original 
script worked fine.

Given below is the traceback.


C:\Documents and Settings\rupeshpradhan\Desktop\scripts>python 
extract_mysql_models.py rupesh:password@rockvale
Traceback (most recent call last):
File "extract_mysql_models.py", line 106, in 
print mysql(m.group(3),m.group(1),m.group(2))
File "extract_mysql_models.py", line 62, in mysql
stderr=subprocess.PIPE)
File "D:\Python25\lib\subprocess.py", line 594, in __init__
errread, errwrite)
File "D:\Python25\lib\subprocess.py", line 822, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified


[web2py] Re: Importing an already existing MySQL database

2011-02-17 Thread Rupesh Pradhan

I have web2py_win_1.91.6 and Windows XP Professional OS.

Or do you mean the script folder is in the source code version of Web2Py? I 
am downloading that now and checking it.


[web2py] Re: Importing an already existing MySQL database

2011-02-17 Thread Rupesh Pradhan
I have web2py_win_1.91.6 and Windows XP Professional OS


[web2py] Re: Importing an already existing MySQL database

2011-02-16 Thread DenesL

It is there in all the sources I have:

/web2py_x.xx_dir/scripts/

which version do you have? which OS?.


[web2py] Re: Importing an already existing MySQL database

2011-02-16 Thread Rupesh Pradhan
I could not find the folder or file under web2py folder? Where is it?


[web2py] Re: Importing an already existing MySQL database

2011-02-15 Thread DenesL

Hi Rupesh,

this is an old thread from 2009, the script is there:
/scripts/extract_mysql_models.py


On Feb 15, 5:28 am, Rupesh Pradhan  wrote:
> Sweet! Boriel!!
>
> Just what the doctor ordered!
>
> Hey, If you happen to polish the script any further and have a new version
> of the same, just remember, I am here to put it to good use. I have
> subscribed to this thread, so that I know if you have put up anything here.
>
> Also, Massimo, have you put the script yet in the 'scrpts' folder like you
> said in version 1.91.6?


[web2py] Re: Importing an already existing MySQL database

2011-02-15 Thread Rupesh Pradhan

Sweet! Boriel!!

Just what the doctor ordered!

Hey, If you happen to polish the script any further and have a new version 
of the same, just remember, I am here to put it to good use. I have 
subscribed to this thread, so that I know if you have put up anything here.

Also, Massimo, have you put the script yet in the 'scrpts' folder like you 
said in version 1.91.6?