The pedestrian detection system we developed before has roughly completed the internal test, and we have combined the self-developed pedestrian detection system with the ticketing system of a scenic spot. We have shared our development process with you in our previous blog posts, and you can read our previous blog posts for more information.

The main purpose of combining pedestrian detection and ticketing system is to ensure the correspondence between pedestrians and the number of ticket buyers, and obtain the tourist flow and operation information of scenic spots. The main realization method is to compare the total number of people in the ticketing system database with the total number of people in the database analyzed by Python. If the total number of people in the database of the ticket system is large, it is necessary to switch the video source to match the number of people.

During the test in the scenic spot, the scenic spot used a locally stored database and Microsoft SQLServer database server, while other scenic spots used mysql database. The two databases were different, so an error occurred during the test, and the error log was: “Panic: Runtime error: Invalid memory address or nil pointer derefernce [Signal 0xC000005 Code =0x0 ADDR = 0xB0 PC =0xe773ad]”

Program execution error, an invalid memory address or null pointer reference. Instead of assigning a value, the initializer specifies nil, causing the program to call the pointer to report an error.

Code examples:

connArgs := "" value := strings.Index(PlayPoint, "bailong") if value >= 0 { connArgs = fmt.Sprintf("server=%s; user id=%s; password=%s; port=%d; database=%s;" , localdbhost, localdbuser, localdbpass, localport, "BL_Tick_Push") MDB, err = gorm.Open("mssql", connArgs) if err ! = nil { return } MDB.SingularTable(true) } else { connArgs = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s? charset=utf8", tdbuser, tdbpass, tdbhost, tdbport, "orderdata") TDB, err = gorm.Open("mysql", connArgs) if err ! Tdb.logmode (true) db := tdb.db () err = db.ping () if err! = nil { return } db.SetMaxOpenConns(1) TDB.SetLogger(db2.DefaultGormLogger) }Copy the code

Connect two databases, one is mysql, the other is MSSQL, both save a global variable, so we use the database of that global variable, otherwise one of MDB and TDB is nil, use the database query, there will be nil pointer operation.

We will operate the code on MDB and TDB.

sql = fmt.Sprintf(`SELECT * FROM BI_Inpark WHERE inpark_systemdate BETWEEN %s AND %s AND inparktype=1 AND parkid=%s`,
   fmt.Sprintf(`'%d-%d-%d %02d:%02d:%02d.000'`, start.Year(), start.Month(), start.Day(), start.Hour(), start.Minute(), start.Second()),
   fmt.Sprintf(`'%d-%d-%d %02d:%02d:%02d.999'`, end.Year(), end.Month(), end.Day(), end.Hour(), end.Minute(), end.Second()),
   fmt.Sprintf(`'%d'`,point))
TDB.Raw(sql).Scan(&MDatabaseArr)
return MDatabaseArr, MTicketPersonCount(MDatabaseArr)
Copy the code

This code operates on the MSSQL database. The TDB variable stores the value of the mysql database, so the operation of the database global variable is incorrect. Here you need to change TDB to the database of the operation (MSSQL) MDB.