Newbie: Database technique

Joe 'shmengie' Brown joe at overdrivepc.com
Mon Dec 23 11:12:59 EST 2002


Thanks for the suggestions!

I've been creating some simple classes that construct select and insert
statements for the conversion process.  After I get through the conversion,
I might post the classes for others benifit.  A basic set of classes will
facilitate and expedite the initial conversion.

re: translation.  That's a little too dynamic to wrap up in a class for my
purposes.

Got sidetracked and started writing a wrapper class for fields.  Being new
to syntax, I spent a good 8 hours hammering this out and getting it to work.

Plan to use this or something like it for field management, but that's still
a good ways down the learning curve.  Guessing this might be the best way to
manage user input and dynamically updating the database once I start coding
the user interface.

fields.py:
from string import join

class Fields:
    """Fields container

    parameter columns = list[{column:value},{column:value}...]"""
    def __init__(self, columns = None):
        self.data = {}
        for x in range(len(columns)):
            col = columns[x]
            name = col.keys()[0]
            value = col[name]
            print name, value
            self.data[name] = { "value"         : value,
                                "initial_value" : value,
                                "display_size"  : None,
                                "internal_size" : None,
                                "precision"     : None,
                                "scale"         : None,
                                "null_ok"       : None,
                                "type_code"     : None }
    def __getitem__(self,name):
        return self.data[name]["value"]

    def __setitem__(self, name,
                 value = None,
                 initial_value = None,
                 display_size = None,
                 internal_size = None,
                 precision = None,
                 scale = None,
                 null_ok = None,
                 type_code = None):
        try: initial_value=self.data[name][initial_value]
        except: pass
        self.data[name] =  { "value"         : value,
                             "initial_value" : initial_value,
                             "display_size"  : display_size,
                             "internal_size" : internal_size,
                             "precision"     : precision,
                             "scale"         : scale,
                             "null_ok"       : null_ok,
                             "type_code"     : type_code }

if __name__=="__main__":
    #Fields test
    f = Fields([{"name" : "Joe"},{"addr1":"here"}])
    f["addr2"]={"value":1}
    print f["name"]





More information about the Python-list mailing list