#!/usr/bin/env jython

import os
import re
import shutil

# SQL Utility class, for manipulating SQL string commands
class sqlUtility(object):

    # Constructor
    def __init__(self,startString):
        self.fields = []
        self.values = []
        self.startString = startString
        return
    
    def group(self,field,value):
        self.fields.append(field)
        self.values.append(value)
        return

    # result is startString + fields + middleString + values + endString
    def makeRaw(self,middleString,endString):

        output = self.startString + " "

        for i in range(len(self.fields)):
            output += self.fields[i]
            if (i < len(self.fields) - 1):
                output += ", "

        output += " " + middleString + "  "

        for i in range(len(self.values)):
            output += self.values[i]
            if (i < len(self.values) - 1):
                output += ", "
        
        output += " " + endString

        return output

    # result is startString + fields + middleString + values + endString (each value surrounded by '')
    def make(self,middleString,endString):

        output = self.startString + " "

        for i in range(len(self.fields)):
            output += self.fields[i]
            if (i < len(self.fields) - 1):
                output += ", "

        output += " " + middleString + " "

        for i in range(len(self.values)):
            output += "'" + self.values[i] + "'"
            if (i < len(self.values) - 1):
                output += ", "
        
        output += " " + endString

        return output

    # result is startString + field = value,... + endString
    def makeEquals(self,endString):

        output = self.startString + " "

        for i in range(len(self.fields)):
            output += self.fields[i] + " = " + self.values[i]
            if (i < len(self.fields) - 1):
                output += ", "
        
        output += " " + endString

        return output

    # when we do a sql insert, we have a command that looks like this:
    # INSERT INTO Table (field1, field2,...) OPERATION (value1, value2,...)
    # I want to make it easy to group field1 and value1, etc

    
