215
Points
Questions
41
Answers
56
-
Asked on July 17, 2020 in XML.
DataSet can read an XML, infer schema and create a tabular representation that’s easy to manipulate:
DataSet ip1 = new DataSet(); //a DataSet is a collection of DataTable ip1.ReadXml(@"c:\temp\ip1.xml"); //this will read the xml file and create a table named "ip" with a column "ip_Text" DataSet ip2 = new DataSet(); ip2.ReadXml(@"c:\temp\ip2.xml"); var r1 = ip1.Tables[0].Rows; //could say Tables["ip"] or Tables[0] var r2 = ip2.Tables[0].Rows; //because there is only one table in the set //.Rows is a collection of DataRow, a bit like a 2D array for (int i = 0; i < r1.Count; i++) { //iterate the rows in the collection var a = r1[i][0].ToString().Split('.'); //2D array, indexed by i (the row) and 0 (the first column) a[2] = r2[i][0].ToString().Split('.')[2]; //could also say [i]["ip_Text"] r1[i][0] = string.Join(".", a); //combine our edited array back to string and update the row } ip1.WriteXml(@"c:\temp\ip3.xml"); //write the rows back to xml
A handy tip, when working with data sets and tables, is to set a breakpoint in the IDE (click to the left of the line number so it gains a red dot) after you’ve loaded the set, then run the program. When it stops, point to the dataset variable and wait for the tooltip. It contains a magnifying glass:
Clicking the magnifying glass brings a window you can use to view the data in a grid:
This can be really useful in terms of knowing what indexes or names columns have etc
- 1336 views
- 3 answers
- 0 votes
-
Asked on July 17, 2020 in XML.
This can be done using LINQ to XML (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/linq-to-xml-overview)
You can find below a snipet:
var xmlDoc = XDocument.Parse(xml); var userNumber = 0; foreach (var user in xmlDoc.Element("UserList").Elements("User")) { userNumber++; var accounts = user.Elements("Accounts").Count(); Console.WriteLine($"For User {userNumber}, you have {accounts} Accounts"); }
Don’t forget to add the required usings:
using System.Linq; using System.Xml.Linq;
and to add a reference to System.Xml.XDocument.dll if using .Net Core or System.Xml.Linq.dll for .Net Framework
- 433 views
- 3 answers
- 0 votes
-
Asked on July 17, 2020 in XML.
You can use blob data type for storing xml in Database. if you are using jpa you can refer to below example https://donovanmuller.blog/storing-xml-natively-in-oracle-with-jpa/
- 499 views
- 1 answers
- 0 votes
-
Asked on July 16, 2020 in Mysql.
You can use
ALTER TABLE
to change the datatype of your table column. It can be done as follows –ALTER TABLE table_name MODIFY column_name UNSIGNED INT;
Read more about ALTER TABLE here
- 373 views
- 2 answers
- 0 votes
-
Asked on July 16, 2020 in Mysql.
Two joins are the right way to go. But you need to refer to the aliases:
SELECT t1_1.name, t1_2.name FROM tbl2 t2 JOIN tbl1 t1_1 ON t2.id_tbl1 = t1_1.id JOIN tbl1 t1_2 ON t2.id_tbl1 = t1_2.id;
- 0 views
- 1 answers
- 0 votes
-
Asked on July 16, 2020 in Mysql.
Cast the
limit
to number, because its type isstring
const limit = parseInt(req.params.limit);
- 386 views
- 1 answers
- 0 votes
-
Asked on July 16, 2020 in Mysql.
The typical design for this would be something like:
Holidays --------- ID | Name | .... -------------------------- 1 |Good Friday |... 2 |Easter Monday|... 3 |Christmas Day|... ... States ---------- ID | Name --------------------------- 1 | Connecticut 2 | Texas 3 | Vermont .... State_Holiday ---------------- State_ID | Holiday_ID ---------------------- 1 | 1 2 | 1 3 | 2 .....
By using a table to define which holidays exist, and referring to them via a foreign key (holiday_id), you avoid typos – in design A, someone might enter "good friday" (not capitalization), and your application would be unclear about whether that’s the same as "Good Friday".
Ditto for states – the state abbreviation codes may suffice as primary keys, but I’m not certain they are guaranteed unique (is there another country that uses these codes?)
The joining table State_Holiday makes it easy to find which holidays are observed in a given state, or which states observe a given holiday.
[Edit] Now you’ve outlined your sample use case, imagine executing that using design B.
You’d have to do a whole bunch of string parsing to find out whether a Connecticut has a holiday on a day that falls between date_begin and date_begin + N. You have to handle the delimiter, and the fact you cannot guarantee at a data model level that state codes are 2 characters. The comparison operator would almost certainly be something along the lines of
and state like '*CT*'
, which would perform terribly because indexes don’t work. You’d need application-level logic to make sure the state codes are correct – you can’t enforce referential integrity in the data model.Option A is much simpler – you’re just comparing a bunch of foreign keys, rather doing string comparison. Your referential integrity is enforced by the data model, rather than application logic.
Option A is preferred by people used to working with relational databases; it’s normalized, uses referential integrity and should perform well, no matter how many holidays you have.
Option B is a "NoSQL" approach. That’s a whole different conversation, but I would not force a NoSQL design into a MySQL system.
- 380 views
- 1 answers
- 0 votes
-
Asked on July 16, 2020 in Mysql.
You need to use
-e
before passing the command\. file.sql
, and you need to use quotation marks for the command.For example:
mysql.exe -uroot -proot -e "\. file.sql"
Therefore, you python code should be:
mysql_exe = r'C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe' mysql_dump = r'C:\Users\Philip\OneDrive\Betting\Capra\Tennis\polgara\tests\mysql\schema_belgarath_test_create.sql' mysql_cmd = r'"\. {}"'.format(mysql_dump) args = [mysql_exe, '-uroot', '-proot', '-e', mysql_cmd] subprocess.run(args)
- 451 views
- 1 answers
- 0 votes
-
Asked on July 16, 2020 in Firebase.
What you can do is do navigation guards for the particular order form. You need to make sure that once the user tries to send a request to the server you have a variable that checks the number of times somebody has requested for the operation. Then deny accordingly.
- 484 views
- 3 answers
- 0 votes
-
Asked on July 16, 2020 in Python.
#python3 from tkinter import * window = Tk() window.title ("test") #variables #exp2 = 0 exp = 0 level=0 #exp function def function (): global exp,exp2, level label_1.configure(text="%d" %(exp)+"/10") exp+=1 if exp==10: level+=1 label_4.configure(text=level) exp=0 #labels label_1 = Label (window,text="%d" %(exp)+"/10", bg = 'white', fg ='black') label_2 = Label (window, text = "exp", bg = 'white', fg ='black') label_3 = Label (window, text = "level", bg = 'white', fg ='black') label_4 = Label (window, bg = 'white', fg ='black') #buttons button_1 = Button (window, text = 'click for xp', command = function) #placements label_1.grid (column = 3, row = 2) label_2.grid (column = 3, row = 1) label_3.grid (column = 5 , row = 1) label_4.grid (column = 5, row = 2) button_1.grid (column = 4, row = 4 ) window.mainloop()
Even though I don’t really understand the question, I hope that it answered your question. You can stop the continuous count by removing the label_1.after(500,function). If this answer your question, vote
- 398 views
- 2 answers
- 0 votes