Package orm2 :: Package adapters :: Package mysql :: Module datatypes
[hide private]
[frames] | no frames]

Source Code for Module orm2.adapters.mysql.datatypes

  1  #!/usr/bin/env python 
  2  # -*- coding: iso-8859-1 -*- 
  3   
  4  ##  This file is part of orm, The Object Relational Membrane Version 2. 
  5  ## 
  6  ##  Copyright 2002-2006 by Diedrich Vorberg <diedrich@tux4web.de> 
  7  ## 
  8  ##  All Rights Reserved 
  9  ## 
 10  ##  For more Information on orm see the README file. 
 11  ## 
 12  ##  This program is free software; you can redistribute it and/or modify 
 13  ##  it under the terms of the GNU General Public License as published by 
 14  ##  the Free Software Foundation; either version 2 of the License, or 
 15  ##  (at your option) any later version. 
 16  ## 
 17  ##  This program is distributed in the hope that it will be useful, 
 18  ##  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 19  ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 20  ##  GNU General Public License for more details. 
 21  ## 
 22  ##  You should have received a copy of the GNU General Public License 
 23  ##  along with this program; if not, write to the Free Software 
 24  ##  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 25  ## 
 26  ##  I have added a copy of the GPL in the file gpl.txt. 
 27   
 28   
 29  # Changelog 
 30  # --------- 
 31  # 
 32  # $Log: datatypes.py,v $ 
 33  # Revision 1.4  2007/12/30 00:58:25  diedrich 
 34  # Added binary literal. 
 35  # 
 36  # Revision 1.3  2006/05/13 17:23:41  diedrich 
 37  # Massive docstring update. 
 38  # 
 39  # Revision 1.2  2006/05/10 21:55:41  diedrich 
 40  # Changed default for validators parameter to () rather than None 
 41  # 
 42  # Revision 1.1  2006/05/02 13:32:01  diedrich 
 43  # Ported mysql adapter from orm v.1 
 44  # 
 45  # 
 46  # 
 47  # 
 48   
 49  """ 
 50  This module implements datatype classes that are specific to MySQL 
 51  """ 
 52   
 53  # Python 
 54  import sys 
 55  from types import * 
 56  from string import * 
 57   
 58  # orm 
 59  from orm2.datatypes import * 
 60   
61 -class auto_increment(integer):
62 """ 63 This datatype is for INTEGER columns using MySQL's AUTO_INCREMENT 64 functionality. They usually serve as primary keys. 65 """ 66
67 - def __init__(self, column=None, title=None, 68 validators=(), widget_specs=()):
69 integer.__init__(self, column, title, validators, widget_specs, 70 has_default=True)
71
72 - def __select_after_insert__(self, dbobj):
73 # When we've already got a value, we can't be inserted again. 74 if self.isset(dbobj): 75 tpl = ( self.attribute_name, 76 self.dbclass.__name__, 77 dbobj.__primary_key_column__(), 78 dbobj.__primary_key_literal__(), ) 79 80 raise ObjectAlreadyInserted( 81 "Attribute %s of '%s' (%s=%s) has already been set." % tpl) 82 83 return True
84
85 - def __set__(self, dbobj, value):
86 if self.isset(dbobj): 87 raise ORMException( "A auto_increment property is not mutable, "+\ 88 "once it is on object creation" ) 89 else: 90 integer.__set__(self, dbobj, value)
91 92 93
94 -class binary_literal(sql.literal):
95 - def __init__(self, bindata):
96 self.bindata = bindata
97
98 - def __sql__(self, runner):
99 runner.params.append(self.bindata) 100 101 return "%s"
102
103 -class binary(datatype):
104 python_class = str 105 sql_literal_class = binary_literal
106 107 108 blob = binary 109 blob_literal = binary_literal 110 111 112 113 # Local variables: 114 # mode: python 115 # ispell-local-dictionary: "english" 116 # End: 117