Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83844

Re: MySQL connections

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: MySQL connections
Date 2015-01-15 20:18 -0500
Organization IISS Elusive Unicorn
References <DB3F78F5082B4B31A42C783C4E9BD763@JakesPC> <CAPTjJmpvaNQNVJsmvbH6YGYnQZkofNCS0F+0UFzwsy-NVqv-ug@mail.gmail.com> <5F6F0C3BBA694C15A513F94735D89E18@JakesPC> <CAPTjJmr3nA-g2eGGW1JHK=09FW+fY4dEmPhWCSYmF6xQGvSfbg@mail.gmail.com> <F2BABA3F0B844089BBCAC9950B9C2456@JakesPC>
Newsgroups comp.lang.python
Message-ID <mailman.17775.1421371093.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, 15 Jan 2015 18:40:31 +0200, "Jacob Kruger" <jacob@blindza.co.za>
declaimed the following:


>If you want to check it out, have attached the full code file - might be a 
>bit messy/large - but, effectively, right at bottom, launch an instance of 
>the class a2m, passing through arguments, and then from within __init__ call 
>convertProcess function, which then initiates process, harvesting sort of 
>rendition/version of structure out of MS access database file, makes call to 
>convertSQL to generate structural SQL script, and save it to a file, which 
>then calls convertData function to generate insert statements to populate 
>database, and then that makes a call to convertExport, if you passed a 
>command line argument in requesting mysql, and that's the current issue 
>function - have stripped most of actual functionality out of it, since am 
>just testing, so the first 16 lines of that function are what's relevant at 
>moment - think shouldn't rely on any other self. objects/attributes as such 
>either, unless step-through process is an issue.
>

	I don't intend to study this in much detail but...

	At line 407 you CLOSE the connection to the DBMS.
	At line 414 you invoke sys.exit() -- which means everything from line
415 to 437 is meaningless, and 438-446 will only be invoked if an exception
is caught, which could only be raised in 394-405, and 413-414.

	I have to ask why you even bothered with a "class" -- about the only
purpose that class seems to be serving is to contain the connection
information... There's no obvious state change in the instance -- each
method seems to be a self-contained function. Your main never keeps an
instance of "a2m",

    a2m(s_mdb, s_mdb_pass, s_target, s_target_value)

will create an instance, and as soon as it returns, throws away the
instance.

	The __init__ calls convertProcess() which calls convertSQL() which
calls convertData() which calls convertExport()... etc.

	There is no modularization, no place to interrupt things...


	You use way too many str() calls -- sys.argv is already a list of
strings...


	Personally, I'd dump the entire thing, get a good set of requirements
for what needs to be done, and then maybe create TWO classes... One class
to encapsulate the JET database operations (JET is the proper name of M$
RDBM using MDB files -- Access is just a GUI report writer/form designer
that uses JET), the other class to encapsulate MySQL operations. The
manipulations to adjust fields from one engine to the other does not belong
in either of the engine specific classes. 

The main logic may be something like:

jet = JET(connection, information)
mysql = MySQL(its, connection, information)

tables = jet.getTableList()
for table in tables:
	tdef = jet.getTableDef(table)
	#manipulate JET table definition to make fit MySQL language
	mysql.createTableDef(table, manipulated_tdef)
	tdata = jet.getTableData(table)
	for rec in tdata:
		#adjust fields to fit MySQL types
		mysql.insertRec(table, adjusted_rec)

etc.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: MySQL connections Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-01-15 20:18 -0500

csiph-web