• 264 Posts
  • 34 Comments
Joined 3 years ago
cake
Cake day: June 11th, 2023

help-circle






















  • Quite a while ago, I wrote this to document my understanding what OOP actually is.

    This sentence at the end is interesting:

    On the other hand it sounds unlikely that there will be a popular language without object-oriented influences some day, so at least minimal syntax-level support is desirable.

    Rust was published like one year later and it can be considered popular by now. Does Rust support OOP via traits? Kind of yes, but so does Haskell with typeclasses.






  • copacetic@discuss.tchncs.detoProgrammer Humor@programming.dev#NULL!
    link
    fedilink
    English
    arrow-up
    20
    ·
    edit-2
    4 months ago

    If you use the SQLite C API like this

        char query[256];
        snprintf(query, sizeof(query),
                 "SELECT * FROM users WHERE username = '%s'", username);
        int rc = sqlite3_exec(db, query, NULL, NULL, &err_msg);
    

    and someone enters Robert'; DROP Table Students;-- as username, it deletes the table Students.

        const char *sql = "SELECT * FROM users WHERE username = ?";
        int rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
        if (rc != SQLITE_OK) {
            fprintf(stderr, "Failed to prepare statement\n");
            return;
        }
        sqlite3_bind_text(stmt, 1, username, -1, SQLITE_STATIC);
    

    Using this “prepared statement” and “bind”, your code is secured against such SQL injection attacks.