{"record":{"id":"4a5dc20f0f6985fe","repo":"litedb-org/LiteDB","slug":"command","errorCode":null,"errorMessage":"command","messagePattern":"command","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Database/LiteDatabase.cs","lineNumber":261,"sourceCode":"        /// Execute SQL commands and return as data reader.\n        /// </summary>\n        public IBsonDataReader Execute(TextReader commandReader, BsonDocument parameters = null)\n        {\n            if (commandReader == null) throw new ArgumentNullException(nameof(commandReader));\n\n            var tokenizer = new Tokenizer(commandReader);\n            var sql = new SqlParser(_engine, tokenizer, parameters);\n            var reader = sql.Execute();\n\n            return reader;\n        }\n\n        /// <summary>\n        /// Execute SQL commands and return as data reader\n        /// </summary>\n        public IBsonDataReader Execute(string command, BsonDocument parameters = null)\n        {\n            if (command == null) throw new ArgumentNullException(nameof(command));\n\n            var tokenizer = new Tokenizer(command);\n            var sql = new SqlParser(_engine, tokenizer, parameters);\n            var reader = sql.Execute();\n\n            return reader;\n        }\n\n        /// <summary>\n        /// Execute SQL commands and return as data reader\n        /// </summary>\n        public IBsonDataReader Execute(string command, params BsonValue[] args)\n        {\n            var p = new BsonDocument();\n            var index = 0;\n\n            foreach (var arg in args)\n            {","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Database/LiteDatabase.cs#L243-L279","documentation":"Thrown by LiteDatabase.Execute(string command, BsonDocument parameters) when the SQL command string is null. The method immediately guards 'command == null' with ArgumentNullException before constructing the Tokenizer, because a null string cannot be tokenized or parsed. This is the primary entry point for raw SQL execution against the engine.","triggerScenarios":"Calling db.Execute((string)null), db.Execute(null as string), or passing a variable that evaluates to null. Also reached indirectly via the Execute(string command, params BsonValue[] args) overload, which forwards a null command into this method.","commonSituations":"Reading SQL from a config file or environment variable that is unset/empty, passing a user-supplied query without null-checking, conditionally building a command string that stays null, or deserializing a command from JSON where the field is absent.","solutions":["Null-check the command string before calling Execute and return early or throw a domain-specific error.","Use string.IsNullOrWhiteSpace to also reject blank/whitespace commands, which would otherwise fail later in the tokenizer.","If the command originates from configuration, validate it at startup rather than at query time."],"exampleFix":"// before\ndb.Execute(userQuery, parameters);\n\n// after\nif (string.IsNullOrWhiteSpace(userQuery))\n    throw new InvalidOperationException(\"SQL command was not supplied.\");\ndb.Execute(userQuery, parameters);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(command))\n    throw new ArgumentException(\"A non-empty SQL command is required.\", nameof(command));","typeGuard":null,"tryCatchPattern":"try { db.Execute(command, parameters); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"command\")\n{\n    // log and surface a clearer domain error to the caller\n}","preventionTips":["Centralize SQL execution behind a helper that null-checks the command.","Validate command strings at startup when they come from config files."],"tags":["sql","argument-null","execute","litedb"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}