Skip to content
Snippets Groups Projects
Commit c92cb3da authored by Stephan Philips's avatar Stephan Philips
Browse files

testing db stugg

parent 58ade070
No related branches found
No related tags found
No related merge requests found
README.md
setup.py
core_tools/__init__.py
core_tools.egg-info/PKG-INFO
......@@ -34,13 +35,8 @@ core_tools/GUI/param_viewer/param_viewer_GUI_window.py
core_tools/HVI/__init__.py
core_tools/HVI/charge_stability_diagram/HVI_charge_stability_diagram.py
core_tools/HVI/charge_stability_diagram/__init__.py
core_tools/HVI/charge_stability_diagram_fast/HVI_charge_stability_diagram.py
core_tools/HVI/charge_stability_diagram_fast/__init__.py
core_tools/HVI/single_shot_exp/HVI_single_shot.py
core_tools/HVI/single_shot_exp/__init__.py
core_tools/HVI/single_shot_exp_SD_corr/HVI_single_shot.py
core_tools/HVI/single_shot_exp_SD_corr/__init__.py
core_tools/HVI/single_shot_exp_SD_corr/generate_SD_corr_sequence.py
core_tools/sweeps/__init__.py
core_tools/sweeps/pulse_lib_sweep.py
core_tools/sweeps/Modulated_scans/DEMOD_tests.py
......
from dataclasses import dataclass
@dataclass
class column_prop:
field_name : str
data_type : str
null : str
key : str
default : str
extra : str
privileges : str = None
comment : str = None
__eq__(self, other):
if isinstance(other, string):
if self.field_name==other:
return True
raise ValueError("comparison not type {} not supported.".format(type(other)))
def checkTableExists(cursor, table_name):
'''
check is a table exists in the db (expected to be selected before)
Args:
cursor ():
table_name (str) : name of the table to check
'''
cursor.execute("SELECT COUNT(*) FROM information_schema.tables WHERE table_name = %s", (table_name, ))
if cursor.fetchone()[0]:
return True
return False
def getColumnNames(cursor, table_name):
'''
get call the column names out of the db
Args:
cursor ():
table_name (str) : name of the table to check
'''
cursor.execute("SHOW COLUMNS FROM {}".format(table_name))
return cursor.fetchall()
\ No newline at end of file
'''
classes that automate the saving an collection of data of a parameter on the database
'''
from qcodes import Parameter, Instrument
from dataclasses import dataclass
from core_tools.db_tools.db_help_funtions import checkTableExists, getColumnNames
import logging
@dataclass
class db_field:
name : Parameter
field_type : str
value : any = None
def define_table(cursor, table_name, fields):
'''
define a paramter in the db, if does not exist, field are the field that are expected to be present.
Args:
cursor () : db cursor
table_name (str) : name of the table to write to the db (e.g. the insturment names which generaters the paramters)
fields (list<db_field>) : field to write
'''
# check if instrument present / create db if needed
if not checkTableExists(cursor, table_name):
cursor.execute("CREATE TABLE %s (snapshot_id INT AUTO_INCREMENT PRIMARY KEY,)", (table_name, ))
logging.info('generated a new table in db, {}'.format(table_name))
# for every field, check if the column exists
pass
def remove_table(cursor, param):
'''
removes a table out of the db (if needed)
'''
pass
def write_to_db(cursor, param, fields):
'''
perform a write if fuekd in the db
'''
pass
def get_snapshot_names(cursor, param, contains, N = 10):
'''
get names of snapshots
'''
pass
def get_data(cursor, parameter, snapshot_id=-1):
'''
get data by primary key, if -1, get latest entry
'''
pass
if __name__ == '__main__':
from qcodes.tests.instrument_mocks import DummyInstrument
import mysql.connector
dac = DummyInstrument('dac', gates=['ch1', 'ch2'])
# print(dac.print_readable_snapshot())
db = mysql.connector.connect(user='stephan', password='magicc',
host='51.89.64.39',
database='qcodes_test')
## creating an instance of 'cursor' class which is used to execute the 'SQL' statements in 'Python'
cursor = db.cursor()
cursor.execute("USE testing")
print(checkTableExists(cursor, 'table_prim_key'))
print(getColumnNames(cursor, 'table_prim_key'))
db.close()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment