clone wizard code

SiOK...? 24 Maggio 2017: SQLDATA e myDBApp + usersDBApp usano istruzioni SQL differenti da sqlite, in fase di connessione ma puoi usare anche database firebird e mariadb.

Lo scopo di myDBApp e memorizzare come se fossero delle semplici stampe i piccoli programmi  per la gestione delle tabelle  organizzate e accessibili con linguaggio SQL.

Potendo eseguire il codice e verificare se questo contiene le funzioni di base da utilizzare, possiamo clonare semplicemente il codice con altro nome ho volendo con lo stesso nome esempio(myApp) una volta personalizzato il nostro programma possiamo inserirlo nel database con numero di versione e altre informazioni esempio data o aggiungere tutto quelo che ci necessità, evitando di gestire il codice in file e cartelle sul file system.     

Questi piccoli programmi GUI python sono in grado di gestire tabelle anche di grandi dimensioni  molto velocemente potendo  disattivare la parte grafica, non solo disattivando i vincoli con la parte grafica puoi usare un qualsiasi programma per interrogare il data base e le relative tabelle.

Abiword HTML Document

clone examples sqlite3

sqlitetest.py

#!/usr/bin/python

# skole pi-ppo

import sqlite3 as lite

import sys

database="skole.db"

con = None

try:

   con = lite.connect(database)

   cur = con.cursor()

   cur.execute('SELECT SQLITE_VERSION()')

   data = cur.fetchone()

   print "SQLite version: %s" % data

except lite.Error, e:

   print "Error %s:" % e.args[0]

   sys.exit(1)

finally:

   if con:

       con.close()

createtable.py

#!/usr/bin/python

# skole pi-ppo

import sqlite3

database="skole.db"

table="DIARY"

conn = sqlite3.connect(database)

print "Opened database: %s successfully" % database;

conn.execute('''CREATE TABLE %s

      (ID INT PRIMARY KEY NOT NULL,

      NAME TEXT    NOT NULL,

      AGE INT     NOT NULL,

      ADDRESS CHAR(50),

      EMAIL CHAR(512),

      PHONE REAL);'''% table)

print "Table %s created on database successfully" % table;

conn.close()

insert.py

#!/usr/bin/python

# skole pi-ppo

import sqlite3

database="skole.db"

table="DIARY"

conn = sqlite3.connect(database)

print "Opened database: %s successfully" % database;

conn.execute("INSERT INTO %s (ID,NAME,AGE,ADDRESS,EMAIL,PHONE) \

     VALUES (1, 'Fiorenzo', 51, 'Italy', 'infoA@it.com', 333998787 )"% table);

conn.execute("INSERT INTO %s (ID,NAME,AGE,ADDRESS,EMAIL,PHONE) \

     VALUES (2, 'Lee', 39, 'China', 'infoB@it.com', 338093882 )"% table);

conn.execute("INSERT INTO %s (ID,NAME,AGE,ADDRESS,EMAIL,PHONE) \

     VALUES (3, 'Ute', 54, 'Norvegian', 'infoC@nl.com', 27881789 )"% table);

conn.execute("INSERT INTO %s (ID,NAME,AGE,ADDRESS,EMAIL,PHONE) \

     VALUES (4, 'Elyan', 46, 'Sveden', 'infoD@sv.com', 37828718 )" % table);

conn.commit()

print "Operation insert records on table %s successfully done" % table;

conn.close()

select.py

#!/usr/bin/python

# skole pi-ppo

import sqlite3

database="skole.db"

table="DIARY"

conn = sqlite3.connect(database)

print "Opened database: %s successfully" % database;

cursor = conn.execute("SELECT id, name, age, address, email, phone  from %s" % table)

for row in cursor:

  print "ID = ", row[0]

  print "NAME = ", row[1]

  print "AGE = ", row[2]

  print "ADDRESS = ", row[3]

  print "EMAIL = ", row[4]

  print "PHONE = ", row[5], "\n"

print "Operation table: %s successfully done" % table;

conn.close()

update.py

#!/usr/bin/python

import sqlite3

database="skole.db"

table="DIARY"

conn = sqlite3.connect('skole.db')

print "Opened database: %s successfully" % database;

conn.execute("UPDATE %s set PHONE = 99999999.33 where ID=1" % table)

print "Total number of rows updated :", conn.total_changes

cursor = conn.execute("SELECT id, name, age, address, email, phone  from %s" % table)

for row in cursor:

  print "ID = ", row[0]

  print "NAME = ", row[1]

  print "AGE = ", row[2]

  print "ADDRESS = ", row[3]

  print "EMAIL = ", row[4]

  print "PHONE = ", row[5], "\n"

conn.commit()

print "Operation update records on table %s successfully done" % table;

conn.close()

delete.py

#!/usr/bin/python

# skole pi-ppo

import sqlite3

database="skole.db"

table="DIARY"

conn = sqlite3.connect(database)

print "Opened database: %s successfully" % database;

conn.execute("DELETE from %s where ID=2;" % table)

print "Total number of rows deleted :", conn.total_changes

cursor = conn.execute("SELECT id, name, age, address, email, phone  from %s" % table)

for row in cursor:

  print "ID = ", row[0]

  print "NAME = ", row[1]

  print "AGE = ", row[2]

  print "ADDRESS = ", row[3]

  print "EMAIL = ", row[4]

  print "PHONE = ", row[5], "\n"

conn.commit() #solo quando si e' sicuri: cancelazione non logica(fisica!!!)

print "Operation delete records on table %s successfully done" % table;

conn.close()

Abiword HTML Document

#!/usr/bin/python

# skole pi+ppo clone this examples from www there are more examples.

# example write html code with python

filename='helloworld.html'

URL='/root/py/examples/html/'

f = open(URL+ filename,'w')

htmlcode = """<html>

<head></head>

<body><p>Hello HTML World!</p></body>

</html>"""

f.write(htmlcode)

print ("creato il file %s") % filename

f.close()

Abiword HTML Document

# skole pi+ppo clone this examples from www there are more examples.

import webbrowser

filename='helloworld.html'

URL='/root/py/examples/html/'

f = open(URL+ filename,'w')

htmlcode = """<html>

<head></head>

<body><p>Hello HTML World!</p></body>

</html>"""

f.write(htmlcode)

print ("creato il file %s") % filename

f.close()

#path location

filename = 'file:/root/py/examples/html/' + filename

print ("apre per la verifica con il browser di default  %s") % filename

webbrowser.open_new_tab(filename)

CONTACT US

 

  Tel: .....

FOLLOW US

PROFILE

Profile ...

© Copyright 2016-2019 All Rights Reserved.