Project

General

Profile

1
import psycopg2
2
import MySQLdb
3
import datetime
4
from xml.dom import minidom
5
from xml.dom.minidom import getDOMImplementation
6
from bien.v.models import *
7

    
8
mysqldb = MySQLdb.connect(host="localhost", user="admin", passwd="lae5eiNa",db="bien2")
9
mysqlcursor = mysqldb.cursor()
10

    
11
psqlconn = psycopg2.connect("dbname=bien_test user=bien_dba password=bien")
12
psqlconn.set_client_encoding('LATIN1')
13
psqlcur = psqlconn.cursor()
14

    
15
system = "BIEN2"
16
scope = "system"
17

    
18
entryInfoInsertBeginning = 'INSERT INTO v_entryinfo ("creationDate","lastUpdatedDate","dataSource") VALUES'
19
vegXInsertBeginning = 'INSERT INTO v_vegx ("entryInfo_id","projects_id") VALUES'
20
projectsInsertBeg = 'INSERT INTO v_projects ("entryInfo_id") VALUES'
21
projectInsertBeg = 'INSERT INTO v_researchprojecttype ("entryInfo_id","projects_id_id","attr_id","attr_system","attr_scope") VALUES'
22
projTitleInsertBeg = 'INSERT INTO v_researchprojecttype_title ("entryInfo_id","ResearchProjectType_id_id","primitive_type_value") VALUES'
23

    
24
batchSize = 500
25

    
26
maxEISql = 'select max(id) from v_entryinfo'
27
psqlcur.execute(maxEISql)
28
maxEntryInfo = psqlcur.fetchone()[0]
29

    
30
maxProjectsSQL = 'select max(id) from v_projects'
31
psqlcur.execute(maxProjectsSQL)
32
maxProjects = psqlcur.fetchone()[0]
33
if maxProjects == None:
34
  maxProjects = 0
35

    
36
maxProjectSQL = 'select max(id) from v_researchprojecttype'
37
psqlcur.execute(maxProjectSQL)
38
maxProject = psqlcur.fetchone()[0]
39
if maxProject == None:
40
  maxProject = 0
41

    
42
getSql = 'SELECT distinct(DBSourceName) from PlotMetaDataDimension'
43
mysqlcursor.execute(getSql)
44
result = mysqlcursor.fetchall()
45

    
46
eii = entryInfoInsertBeginning
47
vxi = vegXInsertBeginning
48
psi = projectsInsertBeg
49
pi = projectInsertBeg
50
pti = projTitleInsertBeg
51

    
52
maxEntryInfo = 1699127
53
maxProjects = 40
54
maxProject = 20
55

    
56
iterCt = 0
57
for record in result:
58
  iterCt = iterCt + 1
59
  eii = eii + "('" + datetime.date.today().strftime("%Y-%m-%d") + "','" + datetime.date.today().strftime("%Y-%m-%d") + "','BIEN2'), "
60
  psi = psi + '(' + str(maxEntryInfo + iterCt) + '), '
61
  vxi = vxi + '(' + str(maxEntryInfo + iterCt) + ',' + str(maxProjects + iterCt) + '), '
62
  pi = pi + '(' + str(maxEntryInfo + iterCt) + ',' + str(maxProjects + iterCt) + ",'BIEN2_" + str(record[0]) + "','" + system + "','" + scope + "'), "
63
  pti = pti + '(' + str(maxEntryInfo + iterCt) + ',' + str(maxProject + iterCt) + ",'BIEN2_" + str(record[0]) + "'), "
64
  if iterCt % batchSize == 0 or iterCt == len(result):
65
#    psqlcur.execute(eii[:(len(eii)-2)])
66
#    psqlconn.commit()
67
    psqlcur.execute(psi[:(len(psi)-2)])
68
    psqlconn.commit()
69
    psqlcur.execute(vxi[:(len(vxi)-2)])
70
    psqlconn.commit()
71
    psqlcur.execute(pi[:(len(pi)-2)])
72
    psqlconn.commit()
73
    psqlcur.execute(pti[:(len(pti)-2)])
74
    psqlconn.commit()
75
    eii = entryInfoInsertBeginning
76
    vxi = vegXInsertBeginning
77
    psi = projectsInsertBeg
78
    pi = projectInsertBeg
79
    pti = projTitleInsertBeg
80

    
81

    
82
psqlconn.rollback()
83

    
84
INSERT INTO v_entryinfo ("creationDate","lastUpdatedDate","dataSource") VALUES('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2'), ('2010-12-01','2010-12-01','BIEN2')
(11-11/21)