24 ottobre 2013.openerp.it XML-RPC vs Psycopg2 Dr. Piero Cecchi. OpenERP Analisi Prestazionale Python script XML-RPC vs Psycopg2



Similar documents
SQL: Programming. Introduction to Databases CompSci 316 Fall 2014

Writing MySQL Scripts With Python's DB-API Interface

Writing MySQL Scripts with Python DB-API

OpenERP: 100% pythonic way for business management

SQL Injection Vulnerabilities in Desktop Applications

IRC Bots. Lance Buttars AKA Nemus. Code From This Talk

How and When to Use Dynamic Lookups

Using IRDB in a Dot Net Project

How to write a bash script like the python? Lloyd Huang. KaLUG - Kaohsiung Linux User Group COSCUP Aug

Persistent Stored Modules (Stored Procedures) : PSM

Cifratura Dati in Tabelle MySQL

Advanced PostgreSQL SQL Injection and Filter Bypass Techniques

Streaming multimedia les from relational database

How to Set Up pgagent for Postgres Plus. A Postgres Evaluation Quick Tutorial From EnterpriseDB

MySQL Fabric: High Availability Solution for Connector/Python

Programming in Python V: Accessing a Database

College Tuition: Data mining and analysis

Database Programming. Week *Some of the slides in this lecture are created by Prof. Ian Horrocks from University of Oxford

Package sjdbc. R topics documented: February 20, 2015


Open source framework for interactive data exploration in server based architecture

WI005 - Offline data sync con SQLite in Universal Windows Platform

SQL Injection 2.0: Bigger, Badder, Faster and More Dangerous Than Ever. Dana Tamir, Product Marketing Manager, Imperva

Oracle Database 12c: SQL Tuning for Developers. Sobre o curso. Destinatários. Oracle - Linguagens. Nível: Avançado Duração: 18h

Relational databases and SQL

PostgreSQL Functions By Example

PostgreSQL as an integrated data analysis platform

Bernd Ahlers Michael Friedrich. Log Monitoring Simplified Get the best out of Graylog2 & Icinga 2

Connecting to a Database Using PHP. Prof. Jim Whitehead CMPS 183, Spring 2006 May 15, 2006

src Documentation Release Pierre Humblot

SQL and Java. Database Systems Lecture 19 Natasha Alechina

Python. Data bases. Marcin Młotkowski. 8th May, 2013

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

Automated ETL Testing with Py.Test. Kevin A. Smith Senior QA Automation Engineer Cambia Health Solutions

CPE111 COMPUTER EXPLORATION

TimesTen Auditing Using ttaudit.java

CPSC 3375 Final Project ER Diagram

How To Use Postgresql With Foreign Data In A Foreign Server In A Multi Threaded Database (Postgres)

Geodatabase Programming with SQL

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

SQL Server Introduction to SQL Server SQL Server 2005 basic tools. SQL Server Configuration Manager. SQL Server services management

Lab 2: PostgreSQL Tutorial II: Command Line

Using Python, Django and MySQL in a Database Course

Maintaining Stored Procedures in Database Application

1. What is SQL Injection?

Using SAS ACCESS to retrieve and store data in relational database management systems

Serious Threat. Targets for Attack. Characterization of Attack. SQL Injection 4/9/2010 COMP On August 17, 2009, the United States Justice

Monitoring Agent for PostgreSQL Fix Pack 10. Reference IBM

In This Lecture. Security and Integrity. Database Security. DBMS Security Support. Privileges in SQL. Permissions and Privilege.

Relational Databases. Charles Severance

ULTEO OPEN VIRTUAL DESKTOP V4.0

SQL Injection. Slides thanks to Prof. Shmatikov at UT Austin

LSINF1124 Projet de programmation

A table is a collection of related data entries and it consists of columns and rows.

Python and MongoDB. Why?

Java and Databases. COMP514 Distributed Information Systems. Java Database Connectivity. Standards and utilities. Java and Databases

Copying data from SQL Server database to an Oracle Schema. White Paper

CS346: Database Programming.

CHAPTER 5 INTELLIGENT TECHNIQUES TO PREVENT SQL INJECTION ATTACKS

Medstrat EMR API. Introduction. Division of Labor API

An Interface from YAWL to OpenERP

Oracle Database 10g Express

Databases and SQL. The Bioinformatics Lab SS Wiki topic 10. Tikira Temu. 04. June 2013

What is ODBC? Database Connectivity ODBC, JDBC and SQLJ. ODBC Architecture. More on ODBC. JDBC vs ODBC. What is JDBC?

Darshan Institute of Engineering & Technology PL_SQL

Managing rights in PostgreSQL

SQL Injection. SQL Injection. CSCI 4971 Secure Software Principles. Rensselaer Polytechnic Institute. Spring

Open Object Developer Book

dbext for Vim David Fishburn h5p://

Integration of Nagios monitoring tools with IBM's solutions

Advanced Web Security, Lab

Exposed Database( SQL Server) Error messages Delicious food for Hackers

Archive Server for MDaemon disaster recovery & database migration

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

Threat Modeling. Categorizing the nature and severity of system vulnerabilities. John B. Dickson, CISSP

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

Client Side Cross Site Scripting

SalesJunction.com. Sales Force Automation & CRM. SJAPI Guide

IVR Security:- Internal A3acks Via Phone Line

Installation and configuration op5 Oracle Extension

How-To: MySQL as a linked server in MS SQL Server

"SQL Database Professional " module PRINTED MANUAL

A Brief Introduction to MySQL

Accessing External Databases from Mobile Applications

An extension to DBAPI 2.0 for easier SQL queries

Programming in postgresql with PL/pgSQL. Procedural Language extension to postgresql

Detecting SQL Injection Vulnerabilities in Web Services

Application note: Connecting the to a Database

Database Driven Websites Using PHP with Informix

DBI-Link: 3.0. PgCon Ottawa 2008 Copyright David Fetter 2008 All Rights Reserved

Transcription:

24 ottobre 2013.openerp.it XML-RPC vs Psycopg2 Dr. Piero Cecchi OpenERP Analisi Prestazionale Python script XML-RPC vs Psycopg2

PROBLEMA REALE In un database nella Tabella: account_move il Campo: id_partner Non è sempre presente 2

TUTTI I MOVIMENTI SENZA PARTNER SONO ABBINATI AL PRIMO ID_PARTNER DELLA TABELLA account_move_line 3

TABELLA account_move_line 4

SCRITTO PROGRAMMA IN PYTHON E XML-RPC... # SEARCH ID ACCOUNT MOVE LINE args = [('state', '=', 'valid')] ids = sock.execute(dbname, uid, pwd, 'account.move.line', 'search', args) splitids=str(ids).split(',') print splitids rowcount=1 for row in splitids: if rowcount == len(ids): idmove = int(row[1:-1]) else: idmove=int(row[1:]) print idmove fields = ['partner_id','move_id'] #fields to read data = sock.execute(dbname, uid, pwd, 'account.move.line', 'read',idmove, fields) splitdata = str(data).split(',') if splitdata[0][15:] <> 'False': idpartner = int(splitdata[0][16:]) print data...esempio read xml-rpc {'partner_id': [231, 'Sguasxxxx Licia'], 'id': 19, 'move_id': [10, 'BNK2/2013/0004']} 5

TABELLA account_move CORRETTAMENTE ABBINATA 6

XML-RPC TIME: 3.27 7

SCRITTO PROGRAMMA IN PYTHON E PSYCOPG2... c_line.execute("select move_id, partner_id, credit, debit FROM account_move_line WHERE (partner_id > 0) ORDER by partner_id") c_line.execute("select DISTINCT move_id, partner_id FROM account_move_line ORDER by partner_id") row_count = 0 for row in c_line: row_count += 1 update_line="update account_move SET partner_id=%s where id=%s" try: c_move.execute(update_line,(row[1],row[0],)) print update_line print "Cursor_row:%s - Partner_id:%s - Move_id:%s" %(row_count, row[1], row[0],) except psycopg2.databaseerror, e: print e.pgcode print e.pgerror sys.exit() c_move.execute("commit") 8

BASIC MODULE USAGE - PSYCOPG2 >>> import psycopg2 # Connect to an existing database >>> conn = psycopg2.connect("dbname=test user=postgres") # Open a cursor to perform database operations >>> cur = conn.cursor() # Execute a command: this creates a new table >>> cur.execute("create TABLE test (id serial PRIMARY KEY, num integer, data varchar);") # Pass data to fill a query placeholders and let Psycopg perform # the correct conversion (no more SQL injections!) >>> cur.execute("insert INTO test (num, data) VALUES (%s, %s)",... (100, "abc'def")) # Query the database and obtain data as Python objects >>> cur.execute("select * FROM test;") >>> cur.fetchone() (1, 100, "abc'def") # Make the changes to the database persistent >>> conn.commit() # Close communication with the database >>> cur.close() >>> conn.close() 9

DATABASE ERROR TEST- PSYCOPG2 #!/usr/bin/python # Replace <USERNAME_DATABASE>, <USERNAME>, and <PASSWORD> below with your actual DB, user, and password. import psycopg2 import sys con = None try: con = psycopg2.connect(database='<username_database>', user='<username>', password='<password>') cur = con.cursor() cur.execute("select * FROM testschema.testtable")1 rows = cur.fetchall() for row in rows: print row except psycopg2.databaseerror, e: print 'Error %s' % e sys.exit(1) finally: if con: con.close() 10

SELECT PSYCOPG2 - TIME: 0.25 11

SELECT DISTINCT PSYCOPG2 - TIME: 0.06 12

SQL EXISTS - UPDATE EXAMPLE UPDATE suppliers SET supplier_name = (select customers.name from customers where customers.customer_id = suppliers.supplier_id) WHERE EXISTS (select customers.name from customers where customers.customer_id = suppliers.supplier_id); 13

SCRITTO PROGRAMMA IN PYTHON E SQL EXISTS... try: conn = psycopg2.connect(conn_string) # print the connection string we will use to connect print "Connecting to database\n->%s" % (conn_string) cur = conn.cursor() update_set = "UPDATE account_move SET partner_id = " update_select = "(SELECT DISTINCT partner_id FROM account_move_line WHERE account_move.id = account_move_line.move_id)" cur.execute(update_set + update_select + " WHERE EXISTS " +update_select) cur.execute("commit") cur.close() conn.close() except psycopg2.databaseerror, e: print e.pgcode print e.pgerror sys.exit() 14

SQL EXISTS PSYCOPG2 TIME 0.02 15

SCRIPT PSQL E SQL EXISTS T="$(date +%s)" psql -U demo -d acsi7demo -c "UPDATE account_move SET partner_id = (SELECT DISTINCT partner_id FROM account_move_line WHERE account_move.id = account_move_line.move_id) WHERE EXISTS (SELECT DISTINCT partner_id FROM account_move_line WHERE account_move.id = account_move_line.move_id)" T="$(($(date +%s)-t))" echo $T 16

SCRIPT PSQL E SQL EXISTS TIME: 0 17

PSQL E SQL EXISTS TIME: 0,034 18

ANALISI PRESTAZIONALE 19

XML-RPC VS PSYCOPG2 XML-RPC VANTAGGI: SICUREZZA CONTROLLO ORM OPENERP UTILIZZO Etichette CAMPI PSYCOPG2 VANTAGGI: VELOCITA' UTILIZZO SQL STANDARD PORTABILITA' QUERY 20

RINGRAZIAMENTI Associazione OpenERP Italia http://www.openerp-italia.org 2013.openerpday.it Italian PostgreSQL Users Group http://www.itpug.org 2013.pgday.it 21

Q&A CONTATTI piero.cecchi@gmail.com software@cecchi.com https://github.com/cecchip/openerpday2013.git 22