<commit_before>#!/neo/opt/bin/python
#
# odb.py
#
# Object Database Api
#
# Written by <NAME> <<EMAIL>>, 2001/07. 
# Inspired by eGroups' sqldb.py originally written by <NAME> circa 1998.
#
# Copyright (C) 2001, by <NAME> and Neotonic
#
# Goals:
#       - a simple object-like interface to database data
#       - database independent (someday)
#       - relational-style "rigid schema definition"
#       - object style easy-access
#
# Example:
#
#  import odb
#  import MySQLdb
#
#  # define table
#  class AgentsTable(odb.Table):
#    def _defineRows(self):
#      self.d_addColumn("agent_id",kInteger,None,primarykey = 1,autoincrement = 1)
#      self.d_addColumn("login",kVarString,200,notnull=1)
#      self.d_addColumn("ticket_count",kIncInteger,None)
#
#  if __name__ == "__main__":
#    # open database
#    ndb = MySQLdb.connect(host = 'localhost',
#                          user='username', 
#                          passwd = 'password', 
#                          db='testdb')
#    db = Database(ndb)
#    tbl = AgentsTable(db,"agents")
#
#    # create row
#    agent_row = tbl.newRow()
#    agent_row.login = "foo"
#    agent_row.save()
#
#    # fetch row (must use primary key)
#    try:
#      get_row = tbl.fetchRow( ('agent_id', agent_row.agent_id) )
#    except odb.eNoMatchingRows:
#      print "this is bad, we should have found the row"
#
#    # fetch rows (can return empty list)
#    list_rows = tbl.fetchRows( ('login', "foo") )
#


import string
import sys, zlib
from log import *

import MySQLdb

eNoSuchColumn         = "odb.eNoSuchColumn"
eNonUniqueMatchSpec   = "odb.eNonUniqueMatchSpec"
eNoMatchingRows       = "odb.eNoMatchingRows"
eInternalError        = "odb.eInternalError"
eInvalidMatchSpec     = "odb.eInvalidMatchSpec"
eInvalidData          = "odb.eInvalidData"
eUnsavedObjectLost    = "odb.eUnsavedObjectLost"
eDuplicateKey         = "odb.eDuplicateKey"

#####################################
# COLUMN TYPES                       
################                     ######################
# typename     ####################### size data means:
#              #                     # 
kInteger       = "kInteger"          # -
kFixedString   = "kFixedString"      # size
kVarString     = "kVarString"        # maxsize
kBigString     = "kBigString"        # -
kIncInteger    = "kIncInteger"       # -
kDateTime      = "kDateTime"
kTimeStamp     = "kTimeStamp"
kReal          = "kReal"


DEBUG = 0

##############
# Database
#
# this will ultimately turn into a mostly abstract base class for
# the DB adaptors for different database types....
#

class Database:
    def __init__(self,db):
        self._tables = {}
        self.db = db
        self._cursor = None
        self.compression_enabled = 0

    # __init__ = None
    # list_tables = None   # list_tables() -> ['a_table','b_table']
    # list_fields = None   # list_fields(tbl_name) -> ['
    # checkTable = None    # checkTable
    # createTable

    def defaultCursor(self):
        if self._cursor is None:
            self._cursor = self.db.cursor()
        return self._cursor

    def escape(self,str):
        if str is None:
            return None

        if self.db.__module__ == "sqlite.main":
            return string.replace(str,"'","''")
        else:
            return MySQLdb.escape_string(str)
    def defaultRowClass(self):
	return Row

    def defaultRowListClass(self):
        # base type is list...
	return list
<commit_msg>only string escape strings in odb<commit_after>#!/neo/opt/bin/python
#
# odb.py
#
# Object Database Api
#
# Written by <NAME> <<EMAIL>>, 2001/07. 
# Inspired by eGroups' sqldb.py originally written by <NAME> circa 1998.
#
# Copyright (C) 2001, by <NAME> and Neotonic
#
# Goals:
#       - a simple object-like interface to database data
#       - database independent (someday)
#       - relational-style "rigid schema definition"
#       - object style easy-access
#
# Example:
#
#  import odb
#  import MySQLdb
#
#  # define table
#  class AgentsTable(odb.Table):
#    def _defineRows(self):
#      self.d_addColumn("agent_id",kInteger,None,primarykey = 1,autoincrement = 1)
#      self.d_addColumn("login",kVarString,200,notnull=1)
#      self.d_addColumn("ticket_count",kIncInteger,None)
#
#  if __name__ == "__main__":
#    # open database
#    ndb = MySQLdb.connect(host = 'localhost',
#                          user='username', 
#                          passwd = 'password', 
#                          db='testdb')
#    db = Database(ndb)
#    tbl = AgentsTable(db,"agents")
#
#    # create row
#    agent_row = tbl.newRow()
#    agent_row.login = "foo"
#    agent_row.save()
#
#    # fetch row (must use primary key)
#    try:
#      get_row = tbl.fetchRow( ('agent_id', agent_row.agent_id) )
#    except odb.eNoMatchingRows:
#      print "this is bad, we should have found the row"
#
#    # fetch rows (can return empty list)
#    list_rows = tbl.fetchRows( ('login', "foo") )
#


import string
import sys, zlib
from log import *

import MySQLdb

eNoSuchColumn         = "odb.eNoSuchColumn"
eNonUniqueMatchSpec   = "odb.eNonUniqueMatchSpec"
eNoMatchingRows       = "odb.eNoMatchingRows"
eInternalError        = "odb.eInternalError"
eInvalidMatchSpec     = "odb.eInvalidMatchSpec"
eInvalidData          = "odb.eInvalidData"
eUnsavedObjectLost    = "odb.eUnsavedObjectLost"
eDuplicateKey         = "odb.eDuplicateKey"

#####################################
# COLUMN TYPES                       
################                     ######################
# typename     ####################### size data means:
#              #                     # 
kInteger       = "kInteger"          # -
kFixedString   = "kFixedString"      # size
kVarString     = "kVarString"        # maxsize
kBigString     = "kBigString"        # -
kIncInteger    = "kIncInteger"       # -
kDateTime      = "kDateTime"
kTimeStamp     = "kTimeStamp"
kReal          = "kReal"


DEBUG = 0

##############
# Database
#
# this will ultimately turn into a mostly abstract base class for
# the DB adaptors for different database types....
#

class Database:
    def __init__(self,db):
        self._tables = {}
        self.db = db
        self._cursor = None
        self.compression_enabled = 0

    # __init__ = None
    # list_tables = None   # list_tables() -> ['a_table','b_table']
    # list_fields = None   # list_fields(tbl_name) -> ['
    # checkTable = None    # checkTable
    # createTable

    def defaultCursor(self):
        if self._cursor is None:
            self._cursor = self.db.cursor()
        return self._cursor

    def escape(self,str):
        if str is None:
            return None

        if self.db.__module__ == "sqlite.main":
            if type(str) == type(""):
                return string.replace(str,"'","''")
            elif type(str) == type(1):
                return str
            else:
                raise "unknown column data type: %s" % type(str)
        else:
            return MySQLdb.escape_string(str)
    def defaultRowClass(self):
	return Row

    def defaultRowListClass(self):
        # base type is list...
	return list

{'fraction_non_alphanumeric': 0.14283705890622803, 'fraction_numerical': 0.0063264445381695485, 'mean_word_length': 2.3477647058823528, 'pattern_counts': {'":': 4, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3598202', 'n_tokens_mistral': 2324, 'n_tokens_neox': 2205, 'n_words': 521}