# -*- coding: utf-8 -*-
###############################################################################
#
#    Copyright (C) 2001-2014 Micronaet SRL (<http://www.micronaet.it>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published
#    by the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
import os
import sys

# -----------------------------------------------------------------------------
#                                MYSQL CLASS
# -----------------------------------------------------------------------------
class mysql_connector():
    ''' MySQL connector
    '''
    # -------------------------------------------------------------------------
    #                             Exported function:
    # -------------------------------------------------------------------------
    def search(self, default_code):
        ''' Search product
        '''
        if not self.connection:
            return False
        cr = self.connection.cursor()
        cr.execute('''
            SELECT id_product
            FROM ps_product
            WHERE reference = '%s';
            ''' % default_code)

        import pdb; pdb.set_trace()
        return [item[0] for item in cr.fetchall()]

    # -------------------------------------------------------------------------
    # Constructor:
    # -------------------------------------------------------------------------
    def __init__(self, database, user, password, server='localhost', port=3306, 
            charset='utf8'):
        ''' Init procedure        
        '''
        # Save parameters:
        self.database = database
        self.user = user
        self.password = password
        self.server = server or 'localhost'
        self.port = port or 3306
        self.charset = charset
        self.status = 'connected'
        self.connected = True
        
        try:            
            error = 'Error no MySQLdb installed'
            import MySQLdb, MySQLdb.cursors

            error = 'Error connecting to database: %s:%s > %s [%s]' % (
                self.server,
                self.port,
                self.database,
                self.user,
                )
                
            self.connection = MySQLdb.connect(
                host=self.server,
                user=self.user,
                passwd=self.password,
                db=self.database,
                cursorclass=MySQLdb.cursors.DictCursor,
                charset=self.charset,
                )                        
        except:
            self.status = error
            self.connected = False
        return
    
# -----------------------------------------------------------------------------
#                                 MAIN PROCEDURE    
# -----------------------------------------------------------------------------
def main():
    ''' Main procedure
    '''
    # TODO read condig PHP file
    database = 'database'
    user = 'user'
    password = 'password'
    server = 'localhost'
    port = 3306
    
    mysql_ps = mysql_connector(database, user, password, server, port)
    if not mysql_ps.connected:
        print 'Not connected: %s' % mysql_ps.status
        sys.exit()
    else:    
        return 'Connected'

if __name__ == '__main__':
    main()
    
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

@@ -1458,28 +1458,25 @@
 h(self, 
-default_code
+parameter
 ):%0A     
@@ -1497,35 +1497,125 @@
 product%0A        
-'''
+    parameter = %5B('field', 'operator', 'value')%5D%0A        '''%0A        parameter = parameter%5B0%5D
 %0A        if not 
@@ -1797,94 +1797,152 @@
 ERE 
-reference = '%25s';%0A            ''' %25 default_code)%0A%0A        import pdb; pdb.set_trace()
+%25s %25s '%25s';''' %25 (%0A                parameter%5B0%5D,%0A                parameter%5B1%5D,%0A                parameter%5B2%5D,                %0A                ))%0A
 %0A   
@@ -1959,17 +1959,28 @@
 n %5Bitem%5B
-0
+'id_product'
 %5D for it

use odoo search method