Result getWriteAccessResult(Session session) {

    try {
      if (targetTable != null && !targetTable.isTemp()) {
        session.checkReadWrite();
      }
    } catch (HsqlException e) {
      return Result.newErrorResult(e);
    }

    return null;
  }
  /**
   * Determines if the authorizations are adequate to execute the compiled object. Completion
   * requires the list of all database objects in a compiled statement.
   */
  void checkAccessRights(Session session) {

    if (targetTable != null && !targetTable.isTemp()) {
      Grantee owner = targetTable.getOwner();

      if (owner != null && owner.isSystem()) {
        if (!session.getUser().isSystem()) {
          throw Error.error(ErrorCode.X_42501, targetTable.getName().name);
        }
      }

      if (!session.isProcessingScript) {
        targetTable.checkDataReadOnly();
      }

      session.checkReadWrite();
    }

    if (session.isAdmin()) {
      return;
    }

    for (int i = 0; i < sequences.length; i++) {
      session.getGrantee().checkAccess(sequences[i]);
    }

    for (int i = 0; i < routines.length; i++) {
      if (routines[i].isLibraryRoutine()) {
        continue;
      }

      session.getGrantee().checkAccess(routines[i]);
    }

    for (int i = 0; i < rangeVariables.length; i++) {
      RangeVariable range = rangeVariables[i];

      if (range.rangeTable.getSchemaName() == SqlInvariants.SYSTEM_SCHEMA_HSQLNAME) {
        continue;
      }

      session.getGrantee().checkSelect(range.rangeTable, range.usedColumns);
    }

    switch (type) {
      case StatementTypes.CALL:
        {
          break;
        }
      case StatementTypes.INSERT:
        {
          session.getGrantee().checkInsert(targetTable, insertCheckColumns);

          break;
        }
      case StatementTypes.SELECT_CURSOR:
        break;

      case StatementTypes.DELETE_WHERE:
        {
          session.getGrantee().checkDelete(targetTable);

          break;
        }
      case StatementTypes.UPDATE_WHERE:
        {
          session.getGrantee().checkUpdate(targetTable, updateCheckColumns);

          break;
        }
      case StatementTypes.MERGE:
        {
          session.getGrantee().checkInsert(targetTable, insertCheckColumns);
          session.getGrantee().checkUpdate(targetTable, updateCheckColumns);

          break;
        }
    }
  }