Browse Source

updates

master
F2256342 - Daniel de Oliveira Carvalho 1 year ago
parent
commit
fcd37c4b9f
  1. 103
      lab.ipynb

103
lab.ipynb

@ -253,6 +253,68 @@
"insert_query = \"INSERT IGNORE INTO default.TRANSACTION (ID, TDATE, ACCOUNTID, MEMO, COUNTRY, OUTFLOW, INFLOW, OWNERID, INSTALLMENT_NR, INSTALLMENT_TT, CREATED, UPDATED) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s )\""
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
"def find_owner(queried_id: int):\n",
" from mysql.connector import connect, Error\n",
"\n",
" query = \"SELECT * FROM OWNER\"\n",
"\n",
" try:\n",
" with connect(\n",
" host=\"localhost\",\n",
" user=\"root\",\n",
" password=\"pleasehashapasswordomg\",\n",
" database=\"default\",\n",
" ) as connection:\n",
" print(\"CONNECTED!\", connection)\n",
" with connection.cursor() as cursor:\n",
" cursor.execute(query)\n",
" query_result = cursor.fetchall()\n",
"\n",
" for item in query_result:\n",
" if item[0] == queried_id:\n",
" result = [item[0], item[1]]\n",
" print(\"DONE!\")\n",
" except Error as e:\n",
" print(e)\n",
" finally:\n",
" connection.close()\n",
" return result"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CONNECTED! <mysql.connector.connection_cext.CMySQLConnection object at 0x7d17dc3331d0>\n",
"DONE!\n"
]
},
{
"data": {
"text/plain": [
"[1, 'Daniel']"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"find_owner(1)"
]
},
{
"cell_type": "code",
"execution_count": 6,
@ -2195,6 +2257,47 @@
"import datetime\n",
"datetime.datetime.now().year"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CONNECTED! <mysql.connector.connection_cext.CMySQLConnection object at 0x7d17dc196fc0>\n",
"full result => [(1, 'Daniel', datetime.datetime(2024, 9, 10, 15, 58, 47), None), (2, 'Izabely', datetime.datetime(2024, 9, 10, 15, 59, 51), None)]\n",
"Daniel\n",
"DONE!\n"
]
}
],
"source": [
"from mysql.connector import connect, Error\n",
"\n",
"query = \"SELECT * FROM OWNER\"\n",
"\n",
"try:\n",
" with connect(\n",
" host=\"localhost\",\n",
" user=\"root\",\n",
" password=\"pleasehashapasswordomg\",\n",
" database=\"default\",\n",
" ) as connection:\n",
" print(\"CONNECTED!\", connection)\n",
" with connection.cursor() as cursor:\n",
" cursor.execute(query)\n",
" result = cursor.fetchall()\n",
" print(\"full result =>\", result)\n",
" print(result[0][1])\n",
" print(\"DONE!\")\n",
"except Error as e:\n",
" print(e)\n",
"finally:\n",
" connection.close()"
]
}
],
"metadata": {

Loading…
Cancel
Save