Adjust result when NULL (MSSQL). (#21417)
thiagoftsm committed
Dec 8, 2025 at 14:25 UTC
6b11dc0e8eebbf3556f4ab017144e029dd5f1d70
1 file changed
+84
-2
src/collectors/windows.plugin/MonitorSQL.c
+84
-2
@@ -96,6 +96,9 @@ static ULONGLONG netdata_MSSQL_fill_long_value(SQLHSTMT *stmt, const char *mask,
96
return (ULONGLONG)ULONG_LONG_MAX;
97
}
98
99
+ if (col_data_len == SQL_NULL_DATA)
100
+ db_size = 0;
101
+
102
netdata_MSSQL_release_results(stmt);
103
return (ULONGLONG)(db_size * MEGA_FACTOR);
104
}
@@ -165,6 +168,11 @@ void dict_mssql_fill_instance_transactions(struct mssql_db_instance *mdi)
168
goto enditransactions;
169
}
170
171
+ if (col_object_len == SQL_NULL_DATA)
172
+ object_name[0] = '\0';
173
+ if (col_value_len == SQL_NULL_DATA)
174
+ value = 0;
175
+
176
// We cannot use strcmp, because buffer is filled with spaces instead NULL.
177
if (unlikely(!strncmp(
178
object_name,
@@ -282,6 +290,11 @@ void dict_mssql_fill_transactions(struct mssql_db_instance *mdi, const char *dbn
290
goto endtransactions;
291
}
292
293
+ if (col_object_len == SQL_NULL_DATA)
294
+ continue;
295
+ if (col_value_len == SQL_NULL_DATA)
296
+ value = 0;
297
+
298
// We cannot use strcmp, because buffer is filled with spaces instead NULL.
299
if (unlikely(!strncmp(
300
object_name,
@@ -377,6 +390,11 @@ void dict_mssql_fill_locks(struct mssql_db_instance *mdi, const char *dbname)
390
goto endlocks;
391
}
392
393
+ if (col_object_len == SQL_NULL_DATA)
394
+ continue;
395
+ if (col_value_len == SQL_NULL_DATA)
396
+ value = 0;
397
+
398
char *space = strchr(resource_type, ' ');
399
if (likely(space))
400
*space = '\0';
@@ -472,6 +490,21 @@ int dict_mssql_fill_waits(struct mssql_instance *mi)
490
goto endwait;
491
}
492
493
+ if (col_wait_type_len == SQL_NULL_DATA)
494
+ continue;
495
+ if (col_total_wait_len == SQL_NULL_DATA)
496
+ total_wait = 0;
497
+ if (col_resource_wait_len == SQL_NULL_DATA)
498
+ resource_wait = 0;
499
+ if (col_signal_wait_len == SQL_NULL_DATA)
500
+ signal_wait = 0;
501
+ if (col_max_wait_len == SQL_NULL_DATA)
502
+ max_wait = 0;
503
+ if (col_waiting_tasks_len == SQL_NULL_DATA)
504
+ waiting_tasks = 0;
505
+ if (col_wait_category_len == SQL_NULL_DATA)
506
+ wait_category[0] = '\0';
507
+
508
struct mssql_db_waits *mdw = dictionary_set(mi->waits, wait_type, NULL, sizeof(*mdw));
509
if (!mdw)
510
continue;
@@ -684,6 +717,32 @@ void dict_mssql_fill_replication(struct mssql_db_instance *mdi)
717
goto endreplication;
718
}
719
720
+ if (publisherdb_len == SQL_NULL_DATA)
721
+ publisher_db[0] = '\0';
722
+ if (publication_len == SQL_NULL_DATA)
723
+ publication[0] = '\0';
724
+ if (type_len == SQL_NULL_DATA)
725
+ type = 0;
726
+ if (status_len == SQL_NULL_DATA)
727
+ status = 0;
728
+ if (warning_len == SQL_NULL_DATA)
729
+ warning = 0;
730
+ if (avg_latency_len == SQL_NULL_DATA)
731
+ avg_latency = 0;
732
+ if (retention_len == SQL_NULL_DATA)
733
+ retention = 0;
734
+ if (subscriptioncount_len == SQL_NULL_DATA)
735
+ subscriptioncount = 0;
736
+ if (runningagentcount_len == SQL_NULL_DATA)
737
+ runningdistagentcount = 0;
738
+ if (average_runspeedperf_len == SQL_NULL_DATA)
739
+ average_runspeedPerf = 0;
740
+ if (publisher_len == SQL_NULL_DATA)
741
+ publisher[0] = '\0';
742
+
743
+ if(unlikely(!publisher_db[0] || !publication[0]))
744
+ continue;
745
+
746
snprintfz(key, sizeof(key) - 1, "%s:%s", publisher_db, publication);
747
struct mssql_publisher_publication *mpp =
748
dictionary_set(mdi->parent->publisher_publication, key, NULL, sizeof(*mpp));
@@ -781,6 +840,9 @@ long netdata_mssql_check_permission(struct mssql_instance *mi)
840
goto endperm;
841
}
842
843
+ if (col_data_len == SQL_NULL_DATA)
844
+ perm = 0;
845
+
846
endperm:
847
netdata_MSSQL_release_results(mi->conn->checkPermSTMT);
848
return perm;
@@ -808,13 +870,15 @@ void netdata_mssql_fill_mssql_status(struct mssql_instance *mi)
870
goto enddbstate;
871
}
872
811
- ret = SQLBindCol(mi->conn->dbSQLState, 1, SQL_C_TINYINT, &state, sizeof(state), &col_data_len);
873
+ SQLLEN col_state_len = 0, col_readonly_len = 0;
874
+
875
+ ret = SQLBindCol(mi->conn->dbSQLState, 1, SQL_C_TINYINT, &state, sizeof(state), &col_state_len);
876
if (likely(netdata_mssql_check_result(ret))) {
877
netdata_MSSQL_error(SQL_HANDLE_STMT, mi->conn->dbSQLState, NETDATA_MSSQL_ODBC_PREPARE, mi->instanceID);
878
goto enddbstate;
879
}
880
817
- ret = SQLBindCol(mi->conn->dbSQLState, 3, SQL_C_BIT, &readonly, sizeof(readonly), &col_data_len);
881
+ ret = SQLBindCol(mi->conn->dbSQLState, 3, SQL_C_BIT, &readonly, sizeof(readonly), &col_readonly_len);
882
if (likely(netdata_mssql_check_result(ret))) {
883
netdata_MSSQL_error(SQL_HANDLE_STMT, mi->conn->dbWaitsSTMT, NETDATA_MSSQL_ODBC_PREPARE, mi->instanceID);
884
goto enddbstate;
@@ -826,6 +890,11 @@ void netdata_mssql_fill_mssql_status(struct mssql_instance *mi)
890
goto enddbstate;
891
}
892
893
+ if (col_state_len == SQL_NULL_DATA)
894
+ state = 0;
895
+ if (col_readonly_len == SQL_NULL_DATA)
896
+ readonly = 0;
897
+
898
struct mssql_db_instance *mdi = dictionary_set(mi->databases, dbname, NULL, sizeof(*mdi));
899
if (unlikely(!mdi))
900
continue;
@@ -878,6 +947,11 @@ void netdata_mssql_fill_job_status(struct mssql_instance *mi)
947
goto enddbjobs;
948
}
949
950
+ if (col_job_len == SQL_NULL_DATA)
951
+ continue;
952
+ if (col_state_len == SQL_NULL_DATA)
953
+ state = 0;
954
+
955
struct mssql_db_jobs *mdj = dictionary_set(mi->sysjobs, job, NULL, sizeof(*mdj));
956
if (unlikely(!mdj))
957
continue;
@@ -929,6 +1003,11 @@ void netdata_mssql_fill_user_connection(struct mssql_instance *mi)
1003
goto enduserconn;
1004
}
1005
1006
+ if (col_user_connections_len == SQL_NULL_DATA)
1007
+ connections = 0;
1008
+ if (col_user_bit_len == SQL_NULL_DATA)
1009
+ is_user = 0;
1010
+
1011
if (is_user)
1012
mi->MSSQLUserConnections.current.Data = (ULONGLONG)connections;
1013
else
@@ -973,6 +1052,9 @@ void netdata_mssql_fill_dictionary_from_db(struct mssql_instance *mi)
1052
goto enddblist;
1053
}
1054
1055
+ if (col_data_len == SQL_NULL_DATA)
1056
+ continue;
1057
+
1058
struct mssql_db_instance *mdi = dictionary_set(mi->databases, dbname, NULL, sizeof(*mdi));
1059
if (!mdi)
1060
continue;